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"); | |
9091c930 | 10 | scanf("%s", fname); |
d386f336 JB |
11 | |
12 | fp = fopen(fname, "r"); /* read mode */ | |
13 | if (fp == NULL) { | |
14 | perror("Error while opening the file.\n"); | |
15 | exit(EXIT_FAILURE); | |
16 | } | |
17 | ||
18 | printf("The content of %s file is :\n", fname); | |
19 | ||
20 | while((ch = fgetc(fp)) != EOF) | |
21 | printf("%c", ch); | |
22 | ||
23 | fclose(fp); | |
24 | ||
25 | return EXIT_SUCCESS; | |
26 | } |