2 回答

TA貢獻(xiàn)1963條經(jīng)驗 獲得超6個贊
例程
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
int main()
{
char block[100]="12345";
int out; //文件描述符
int num=100;/*寫入的字節(jié)數(shù)量*/
char * fileName="file.txt";/*要寫入的文件名*/
out = open(fileName, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);/*打開文件寫入*/
write(out,block,num);/*寫入文件*/
return 0;
}

TA貢獻(xiàn)1820條經(jīng)驗 獲得超2個贊
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main()
{
int len = 0;
int fp = 0;
char text[ 20 ] = {'\0'};
char list[ 121 ] = "123456";
fp = open( "文件", O_WRONLY );
len = sprintf( text, "%s" , list );
write( fp, text, len );
close( fp );
return 0;
}
添加回答
舉報