Commit | Line | Data |
---|---|---|
d386f336 JB |
1 | #include <stdio.h> |
2 | #include <stdlib.h> | |
3 | ||
4 | int main() { | |
5 | char ch; | |
6 | char* fname; | |
7 | FILE* fp; | |
8 | ||
9 | printf("Enter the name of the file you wish to see\n"); | |
10 | int prt = scanf("%s", fname); | |
11 | /* if (prt != 0) { | |
12 | perror("Error entering the file name.\n"); | |
13 | exit(EXIT_FAILURE); | |
14 | } */ | |
15 | ||
16 | fp = fopen(fname, "r"); /* read mode */ | |
17 | if (fp == NULL) { | |
18 | perror("Error while opening the file.\n"); | |
19 | exit(EXIT_FAILURE); | |
20 | } | |
21 | ||
22 | printf("The content of %s file is :\n", fname); | |
23 | ||
24 | while((ch = fgetc(fp)) != EOF) | |
25 | printf("%c", ch); | |
26 | ||
27 | fclose(fp); | |
28 | ||
29 | return EXIT_SUCCESS; | |
30 | } |