I am trying to create a simple text file using TurboC++ DOS emulator. But, it's not creating the file. I am referring to an online video where the same file is getting created. What can be the issue?
Below is the code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int num;
FILE *fptr;
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;
}
Although, this answer may no longer be required, I am providing it here for future reference of those who might need it.
I had the same problem some time ago.
It turns out the DOS emulator emulates the PC storage for programs.
The folder C:\TurboC++\Disk is treated as C:\ by TurboC++, and it is the root folder for whatever TurboC++ needs to refer to.
So, your file program.txt, should have the path [Your Installation Path]:\TurboC++\Disk when seen from outside TurboC++.