Advertisement
jfan14

Untitled

Sep 20th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[]) {
  5.   if (argc < 2) {
  6.     printf("Usage: %s FILENAME\n", argv[0]);
  7.     exit(1);
  8.   }
  9.   FILE *fp = fopen(argv[1],"r");
  10.   int buf[2];
  11.  
  12.   if(fp == NULL){
  13.     printf("CANNOT open file");
  14.     exit(1);
  15.   }
  16.   while(1){
  17.     int nread = fread(buf,sizeof(int),2,fp);
  18.     if(nread < 2){
  19.       break;
  20.     }
  21.  
  22.     for(int j=0;j<buf[0];j++){
  23.       fwrite((char)buf[1],sizeof(char),1,stdout);
  24.     }
  25.   }
  26.  
  27.  
  28.   fclose(fp);
  29.   return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement