Created
September 20, 2017 10:16
-
-
Save b8jdkal/99af844f9fe7b1519f911fa79ba5460e to your computer and use it in GitHub Desktop.
用c来读文件, 运行./testcread然后输入文件名
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int main() | |
| { | |
| int d = 0; | |
| char ch, file_name[525]; | |
| FILE *fp; | |
| printf("Enter the name of file you wish to see\n"); | |
| gets(file_name); | |
| fp = fopen(file_name,"r"); // read mode | |
| if( fp == NULL ) | |
| { | |
| perror("Error while opening the file.\n"); | |
| exit(EXIT_FAILURE); | |
| } | |
| printf("The contents of %s file are :\n", file_name); | |
| //while( ( ch = fgetc(fp) ) != EOF ) | |
| while((ch=fgetc(fp)) != EOF ) | |
| d+=1; | |
| printf("%d",d); | |
| fclose(fp); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment