I am having a problem. How can I set up a program so that a user can enter what file he wants to read, including the path.
Code:
#include <stdio.h>
#include <fstream.h>
#include <string>
int main(void)
{
char szInputString[1000];
char szBuffer[10000];
FILE *input_file, *out_file = stdout;
cout << "please enter the text file you would like to read: \n";
cin >> szInputString;
if ((input_file = fopen(szInputString, "r"))==NULL) {
return 1;
}
while ((fgets (szBuffer, sizeof szBuffer, input_file)) != 0)
{
fprintf (out_file, " \n %s", szBuffer);
}
fclose (input_file);
return 0;
}
with the code above, I cant even open it from diff directories.