Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.19 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<conio.h>
  4. #include<ctype.h>
  5. int decode[1000],decodeLen=0;
  6. int hexToDec(char c)
  7. {
  8.     c=toupper(c);
  9.     if(c>='A' && c<='F')
  10.        return c-'A'+10;
  11.     else
  12.        return c-48;
  13. }
  14. void asciiDecode(char str[])
  15. {
  16.      FILE *fpWrite;
  17.      fpWrite=fopen("c:\\score2.txt","at");
  18.      int i,l,x,y,num;
  19.      l=strlen(str);
  20.      for(i=0;i<l;i=i+2)
  21.      {
  22.                       x = hexToDec(str[i]);
  23.                       y = hexToDec(str[i+1]);
  24.                       num=(x*16)+(y*1);
  25.                       if(num>=1 && num<=127)
  26.                       {
  27.                           printf("%c",num);
  28.                           decode[decodeLen]=num;
  29.                           decodeLen++;
  30.                           fprintf(fpWrite,"%c",num);
  31.                       }
  32.                      
  33.      }
  34.      fclose(fpWrite);
  35. }
  36.  
  37. void reverseCode()
  38. {
  39.      FILE *fpWrite;
  40.      fpWrite=fopen("c:\\score2.txt","at");
  41.      int i,j,count;
  42.      count=decodeLen;
  43.      for(i=0;i<decodeLen;i++)
  44.      {
  45.                     if( (i+1)%4==0)
  46.                      {
  47.                          for(j=i;j>=i-3;j--)
  48.                          {
  49.                                             printf("%c",decode[j]);
  50.                                             fprintf(fpWrite,"%c",decode[j]);
  51.                          }
  52.                          count=i;
  53.                      }
  54.                      if(i==decodeLen-1  && i-count < 4)
  55.                      {
  56.                                 for(j=i;j>=count+1;j--)
  57.                                 {
  58.                                                        printf("%c",decode[j]);
  59.                                                        fprintf(fpWrite,"%c",decode[j]);
  60.                                 }
  61.                     }
  62.      }
  63.      fclose(fpWrite);
  64.      
  65. }
  66. int main()
  67. {
  68.     FILE *fp;
  69.     char str[30];
  70.     int i;
  71.     fp = fopen("c://score1.txt","r");
  72.     while(fscanf(fp,"%s",str)!=EOF)            
  73.     {
  74.  
  75.                                       asciiDecode(str);
  76.          
  77.     }
  78.     printf("\n\nAfter Reverse: ");
  79.     reverseCode();                
  80.     fclose(fp);
  81.        
  82.     scanf(" ");
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement