Guest User

read from file to console

a guest
Oct 14th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void p_char(int chr)
  5. {
  6.     putchar (chr);
  7. }
  8.  
  9. int main(int argc, char* argv[])
  10. {
  11.     //char* filename = "mytext.txt";
  12.     char* filename;
  13.  
  14.     if ( (filename = argv[1]) ){
  15.         printf ("file %s открыт:\n",filename);
  16.     }
  17.  
  18.     FILE *fl;
  19.     int c;
  20.  
  21.     fl = fopen (filename,"r");
  22.  
  23.     if (fl == NULL) {
  24.         printf ("укажите имя файла, который надо прочитать: ./my_c.exec mytext.txt\n");
  25.         return 0;
  26.     }
  27.  
  28.     while ( ( c = fgetc (fl) )!= EOF ){
  29.         p_char(c);
  30.     };
  31.  
  32.     fclose(fl);
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment