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.
Here is my code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[])
{
FILE * inputFile = NULL;
char filename[FILENAME_MAX];
char c = ' ';
int number_of_data;
int number;
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 Press Enter to quit", filename );
getchar();
return EXIT_FAILURE;
}
fscanf(inputFile, "%d", &number_of_data);
printf("%d", &number_of_data);
while((c = (char)getc(inputFile)) != EOF)
{
if(c == ' ')
c = ' ';
}
fclose(inputFile);
puts("Press any key to Continue");
getchar();
return EXIT_SUCCESS;
}