Advertisement
Guest User

Untitled

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