2 回答

TA贡献1963条经验 获得超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;/*写入的字节数量*/
char * fileName="file.txt";/*要写入的文件名*/
out = open(fileName, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);/*打开文件写入*/
write(out,block,num);/*写入文件*/
return 0;
}

TA贡献1820条经验 获得超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;
}
- 2 回答
- 0 关注
- 408 浏览
添加回答
举报