fork download
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <stdlib.h>
  4. int main()
  5. {
  6. FILE *fp;
  7. int m,i,j;
  8. char line[10];
  9. if((fp=fopen("水果.txt", "r"))==NULL)
  10. {
  11. printf("無法開啟檔案");
  12. return 1; //exit(1);
  13. }
  14.  
  15. //(比如說我輸入3,出現三個水果名字直到程式結束)
  16. printf("請輸入每行水果個數 M: ");
  17. scanf("%d", &m);
  18.  
  19. for (i = 0; fscanf(fp, "%s\n", line)>0; ++i) {
  20. printf("%s ", line);
  21. if (0==(i+1)%3) printf("\n");
  22. }
  23.  
  24. system("pause");
  25. return 0;
  26. }
Runtime error #stdin #stdout 0s 2424KB
stdin
Standard input is empty
stdout
無法開啟檔案