Input of C program

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    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;
Last edited on
Topic archived. No new replies allowed.