Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(void)
- {
- FILE *fptr; //宣告一個指標fptr指向檔案
- char ch; //宣告字元變數ch,用來接收讀取的字元
- int count=0; //計數器
- fptr=fopen("C:\\Users\\nian\\Desktop\\NFA.txt","r"); //開啟檔案
- if(fptr!=NULL) //若fopen()傳回的值不是NULL,則表示檔案開啟successful
- {
- while((ch=getc(fptr))!=EOF) //若不是EOF則做以下動作
- {
- printf("%c",ch); //印出一個字元
- count++; //計數器加一
- }
- fclose(fptr);
- printf("\n總共有%d個字元\n",count);
- }
- else
- printf("檔案開啟失敗!!\n");
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment