示ä¾æç¨ï¼
1. ç¼å代ç
å¨linuxä¸é¢ä½¿ç¨å½ä»¤å建main.cæ件
vim main.c
main.c代ç ï¼
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#define MAX 50
int main()
{
int fd;
char buf[MAX];
fd = open("1.txt",O_WRONLY|O_CREAT|O_APPEND);
if(fd == -1)
{
printf("æ件å建失败");
return -1;
}
printf("请è¾å
¥è¦åå
¥çå¥åï¼");
fgets(buf,MAX,stdin);
write(fd,buf,MAX);
printf("åå
¥æå\n");
return 0;
}
2.ç¼è¯æºç¨åº
gcc main.c -o main
ç»æå¨æ¤è·¯å²ä¸ä¼åºç°mainæºç¨åº

3.è¿è¡æºç¨åº

æ¥çæ件æ¯å¦å建ä¸åå
¥æå

å®æ