Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. /* ヘッダファイルのインクルード */
  2. #include <stdio.h> /* 標準入出力(ファイル入出力も含む.) */
  3.  
  4. /* main関数の定義 */
  5. int main(void){
  6.  
  7. /* 配列・ポインタの宣言 */
  8. char text[256]; /* test.txtから読み込んだ文字列(最大255( = 256 - 1)文字). */
  9. FILE *fp; /* ファイルポインタfp */
  10.  
  11. /* test.txtを開く. */
  12. fp = fopen("test.txt", "r"); /* test.txtを"r"で開く. */
  13. if (fp == NULL){ /* エラー */
  14.  
  15. /* エラー処理 */
  16. printf("Can't open file!\n");
  17. return -1;
  18.  
  19. }
  20.  
  21. /* test.txtの読み込み. */
  22. fgets(text, 256, fp); /* fgetsでtest.txtから1行読み込み, textに格納する. */
  23.  
  24. /* textの出力. */
  25. printf("%s\n", text); /* printfでtextを出力. */
  26.  
  27. /* test.txtを閉じる. */
  28. fclose(fp); /* fcloseでtest.txtを閉じる. */
  29.  
  30. /* プログラムの終了 */
  31. return 0;
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement