I want the program can do that for me.
When I enter the name of file in the same folder of .exe, the program will scan the file data and print it out the data in order.
However, i do not know how to scan the data in the file and print it out.
And i do not know why i enter the file name( which in the same folder of .exe), and it shows that can't find the file.
FILE * inputFile = NULL;
char filename[FILENAME_MAX];
char c = ' ';
if(argc > 1)
{
strncpy(filename, argv[1], FILENAME_MAX);
}
else
{
puts("Press Enter the name of the File from which to read the data : ");
fgets(filename, FILENAME_MAX, stdin);
}
inputFile = fopen(filename, "r");
if(inputFile == NULL)
{
printf("Cannot open file %s for input. Press Enter to quit", filename );
getchar();
return EXIT_FAILURE;
}
while((c = (char)getc(inputFile)) != EOF)
{
if(c == ' ')
c = '\n';
}
fclose(inputFile);
puts("Press any key to Continue");
getchar();
return EXIT_SUCCESS;