Lisaveta777

Prata list 8.3

Aug 12th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int ch;
  7.     FILE *fp;
  8.     char fname[50];   //for holding file name
  9.  
  10.     printf("Enter file name:");
  11.     scanf("%s",fname); //full path, i did c:\kino1\abc2.txt
  12.     fp = fopen(fname, "r");   //open file for reading
  13.     if (fp == NULL)          //not sucessfull
  14.     {
  15.         printf("Cant open file. Program ended\n");
  16.         exit(1);     //exit programm
  17.     }
  18.     //getc(fp) gets char from open file
  19.     while((ch = getc(fp)) != EOF)
  20.         putchar(ch);
  21.     fclose(fp);       //file closed
  22.  
  23.  
  24.     return 0;
  25. }
Add Comment
Please, Sign In to add comment