PHP Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define BUFFER_SIZE 1000
int main()
{
FILE* FilePointer;
int Variable;
char cBuffer[BUFFER_SIZE+1];
Variable = 42;
/* open for writing a file named test.txt on C: */
FilePointer = fopen( "C:\\test.txt", "w" );
/* check if successfull */
if( FilePointer == NULL )
{
printf( "Unable to open file for writing..." );
return 1;
}
/* write to file */
fprintf( FilePointer,
"Test Text to test file writing and reading. Variable = %d...",
Variable );
Variable = 18745;
/* write to file */
fprintf( FilePointer,
"\nNextLine: Variable = %d...",
Variable );
/* done, close file */
fclose( FilePointer );
/* now test it, by reading and diplaying it */
/* open file for reading*/
FilePointer = fopen( "C:\\test.txt", "r" );
/* check if file found*/
if( FilePointer == NULL )
{
printf( "Unable to open file for reading..." );
return 2;
}
/* while still chars from file unread */
while( ! feof( FilePointer ) )
{
/* read from file */
fgets( cBuffer, BUFFER_SIZE, FilePointer );
/* display line from file */
printf( "Line read from file was:\n[%s]\n", cBuffer );
}
/* close file */
fclose( FilePointer );
getch();
return 0;
}