Saturday, April 26, 2008

A simple C program for writing to a file

Source:http://www.mycplus.com/cplus.asp?CID=8

#include "stdio.h"
main( )
{
FILE *fp;
char stuff[25];
int index;
fp = fopen("TENLINES.TXT","w"); /* open for writing */
strcpy(stuff,"This is an example line.");
for (index = 1; index <= 10; index++)
fprintf(fp,"%s Line number %d\n", stuff, index);
fclose(fp); /* close the file before ending program */
}

No comments: