Guest User

Untitled

a guest
Jan 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void)
  5. {
  6. FILE *fptr; //宣告一個指標fptr指向檔案
  7. char ch; //宣告字元變數ch,用來接收讀取的字元
  8. int count=0; //計數器
  9.  
  10. fptr=fopen("C:\\Users\\nian\\Desktop\\NFA.txt","r"); //開啟檔案
  11. if(fptr!=NULL) //若fopen()傳回的值不是NULL,則表示檔案開啟successful
  12. {
  13. while((ch=getc(fptr))!=EOF) //若不是EOF則做以下動作
  14. {
  15. printf("%c",ch); //印出一個字元
  16. count++; //計數器加一
  17. }
  18. fclose(fptr);
  19. printf("\n總共有%d個字元\n",count);
  20. }
  21.  
  22. else
  23. printf("檔案開啟失敗!!\n");
  24.  
  25. system("pause");
  26. return 0;
  27. }
Add Comment
Please, Sign In to add comment