i have an char
array b[20]
which i want to write into a file . After every iteration the value of b[20]
changes , so i would like to write the string in each line of the file in each iteration . So how can i change a new line in a file a开发者_如何学Gond also put in a array of character?
Something like:
FILE *fp = fopen("file.txt","w");
// check for error
char b[20];
while(some_condition) {
// populate the char array b and terminate it with NULL char.
// write to file...and write a newline.
fprintf(fp,"%s\n",b);
}
Assuming the char array contains a null-terminated string:
fprintf(file, "%.20s\n", b);
精彩评论