Load and display the file named formout.c for your first example of writing data to a file.
#include "/sys/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 */
}
We begin as before with the "include" statement for "stdio.h", then define some variables for use in the example including a rather strange looking new type. The type "FILE" is used for a file variable and is defined in the "stdio.h" file. It is used to define a file pointer for use in file operations. The definition of C contains the requirement for a pointer to a "FILE", and as usual, the name can be any valid variable name.
#include "/sys/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 */
}
We begin as before with the "include" statement for "stdio.h", then define some variables for use in the example including a rather strange looking new type. The type "FILE" is used for a file variable and is defined in the "stdio.h" file. It is used to define a file pointer for use in file operations. The definition of C contains the requirement for a pointer to a "FILE", and as usual, the name can be any valid variable name.

