» Basic File IO in C by Christopher Hill -TrajectoryLabs.com |
| | Page 6 of 7 | |
| < Previous | | Next > |
|
(Login to remove green text ads)
Write lines using fputs()
Code:
// Write lines using fputs()
#include <stdio.h>
int main()
{
FILE *file_ptr; // 1. declare a FILE pointer
char *text = {"Text,\none line at a time."};
int i;
file_ptr = fopen("lines.txt", "w"); // 2. open file
if(file_ptr !=NULL) // 3. test
{
printf("File lines.txt created.\n");
fputs( text, file_ptr ); // 4. write file
fclose(file_ptr); // 5. close the file
return 0;
}
else { printf("Unable to create file.\n"); return 1; }
}
|
| |
| | Page 6 of 7 | |
| < Previous | | Next > |
|
|