open int fd1 = open("fifo1", O_WRONLY); O_RDONLY O_WRONLY
read read(STDIN_FILENO,buf,sizeof(buf)); STDOUT_FILENO STDIN_FILENO
write
close
fopen
fgets
fputs
fread 第一个参数是buf 第二个参数是读取的最小结构的字节大小 第三个参数是结构的数量 如果读取到的结构数量小于第二个参数的字节大小,那么fread返回0
fwrite
fclose
FOPEN/FCLOSE 使用
int main(int arg, char *args[]) {
FILE *p1 = fopen("a.txt", "r");
if (p1 == NULL) {
printf("err is %s\n", strerror(errno));
return -1;
}
int buf[1024];
memset(buf, 0, sizeof(buf));
char val[32];
int len = 0;
while (1) {
memset(val, 0, sizeof(val));
if (fgets(val, sizeof(val), p1) == NULL) {
break;
}
buf[len] = atoi(val);
len++;
}
fclose(p1);
FILE *p2 = fopen("b.txt", "w");
if (p2 == NULL) {
printf("err is %s\n", strerror(errno));
return -1;
}
int i;
for (i = 0; i < len; i++) {
memset(val,0,sizeof(val));
sprintf(val,"%d\n",buf[i]);
fputs(val,p2);
}
fclose(p2);
return 0;
}
网友评论