就像是:
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);
}
Run Code Online (Sandbox Code Playgroud)