Im trying to make a basic open text file, read, write to text file program. However im new to c and the program simply crashes when i run it. When i debug it crashes on the fwritef command
Code:
int main(int argc, char *argv[])
{
FILE *file = fopen( "test.txt", "r" );
FILE *fp = fopen( "out.txt", "w");
if ( file == 0 )
{
printf( "Could not open file\n" );
}
else
{
char x;
while ( ( x = fgetc( file ) ) != EOF )
{
fwritef(fp, x);
}
fclose( fp );
}
fclose( file );
}
i would appreciate if someone could point out what im doing wrong