在线求linux,c高手,会write函数.

来源:百度知道 编辑:UC知道 时间:2024/05/16 05:14:36
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<fcntl.h>
int main()
{int fa;
int s=12;
fa=open("/home/pie/pie.txt".O_WRONLY|O_CREAT)
write(fa,s,sizeof(s));
close(fa);
}
完了提示 未作类型转换..
我就只是想把一个整型数输出到文本文件当中..
如果把 s定义为char [] 型,就可以输出..我现在是要输出整形..请问该怎么办???

#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<fcntl.h>
#include <stdio.h>

int main()
{
int fa;
int s=12;
int len;
char text[20];

fa=open("/home/pie/pie.txt".O_WRONLY|O_CREAT);
len = sprintf(text, "%d", s);
write(fa,text,len);
close(fa);
}