If I write
char ar[100];
strcpy(ar, "I am in child\n");
write(fd, ar, strlen(ar))
It will copy "I am in child" to file located in fd using open function.
But how to write
printf("you got %d points\n",dice);
to another file in C? dice
is an integer.
You should use fprintf()
.
#include <stdio.h>
int main(void) {
int dice = 0;
FILE* fp = fopen("your_file_name.txt", "w");
if (fp == NULL) {
perror("fopen");
return 1;
}
fprintf(fp, "you got %d points\n", dice);
fclose(fp);
return 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.