Hi,
I am learning to program in C but I have encountered a problem. I have the following code:
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num;
FILE *fptr;
// use appropriate location if you are using MacOS or Linux
fptr = fopen("C:\\program.txt","w");
if(fptr == NULL)
{
printf("Error!");
exit(1);
}
printf("Enter num: ");
scanf("%d",&num);
fprintf(fptr,"%d",num);
fclose(fptr);
return 0;
}
When I compile and run this code I get the error message "Error!". So the file "C:\\program.txt" is not created on my harddisk.
Can someone tell me what is going wrong?
Thanks
Ben