daily pastebin goal
88%
SHARE
TWEET

Untitled

a guest Aug 13th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(){
  6.     char fname[500];
  7.     printf("Name of file: ");
  8.     scanf("%s",fname);
  9.     printf("***OUTPUT STARTS ON NEXT LINE*****\n");
  10.     FILE* fin = fopen(fname,"r");
  11.    
  12.     int len=0;
  13.     for(;;){
  14.       if(feof(fin)) break;
  15.       fscanf(fin,"%*c"); ++len;  
  16.     }
  17.     len /= 8;
  18.     rewind(fin);
  19.    
  20.     char **buf = (char**) calloc(len,sizeof(char*));
  21.     for(int i=0;i<len;++i) buf[i] = (char*) calloc(8,sizeof(char));
  22.     int *buf2 = (int*) calloc(len,sizeof(int)); for(int i=0;i<len;++i) buf2[i]=0;
  23.    
  24.     for(int i=0;i<len;++i){
  25.       fscanf(fin,"%8c",buf[i]);
  26.       for(int j=0;j<8;++j){
  27.         int currVal = buf[i][j]-'0';
  28.         for(int k=0;k<7-j;++k) currVal *= 2;
  29.         buf2[i]+=currVal;
  30.       }
  31.       printf("%c",buf2[i]);
  32.     }
  33.     printf("\n***OUTPUT FINISHED ON LAST LINE***\n");
  34.     rewind(stdin);
  35.     getchar();
  36. }
RAW Paste Data
Top