Write some data into file.txt
For fwrite():
…
FILE *fp;
fp = fopen(“file.txt”, “a+”);
//Use this at the first time.
fwrite(“123”, sizeof(“123”), 1, fp);
//Use this after the first time.
//fwrite(“1234”, sizeof(“1234”),1, fp;);
fclose(fp);
…
The program will write “123” into file.txt at the first time running. However after that no matter how many times running the program, the content in file.txt will not be changed but stay as “123”.
The same thing happened when use write():
…
int fd, size_write;
fd = open(“file.txt”, O_WRONLY|O_APPEND);
//first time
size_write = write(fd, “123”, sizeof(“123”));
//after first time
//size_write = write(fd, “1234”, sizeof(“1234”));
close(fd);
…