Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<conio.h>
- #include<ctype.h>
- int decode[1000],decodeLen=0;
- int hexToDec(char c)
- {
- c=toupper(c);
- if(c>='A' && c<='F')
- return c-'A'+10;
- else
- return c-48;
- }
- void asciiDecode(char str[])
- {
- FILE *fpWrite;
- fpWrite=fopen("c:\\score2.txt","at");
- int i,l,x,y,num;
- l=strlen(str);
- for(i=0;i<l;i=i+2)
- {
- x = hexToDec(str[i]);
- y = hexToDec(str[i+1]);
- num=(x*16)+(y*1);
- if(num>=1 && num<=127)
- {
- printf("%c",num);
- decode[decodeLen]=num;
- decodeLen++;
- fprintf(fpWrite,"%c",num);
- }
- }
- fclose(fpWrite);
- }
- void reverseCode()
- {
- FILE *fpWrite;
- fpWrite=fopen("c:\\score2.txt","at");
- int i,j,count;
- count=decodeLen;
- for(i=0;i<decodeLen;i++)
- {
- if( (i+1)%4==0)
- {
- for(j=i;j>=i-3;j--)
- {
- printf("%c",decode[j]);
- fprintf(fpWrite,"%c",decode[j]);
- }
- count=i;
- }
- if(i==decodeLen-1 && i-count < 4)
- {
- for(j=i;j>=count+1;j--)
- {
- printf("%c",decode[j]);
- fprintf(fpWrite,"%c",decode[j]);
- }
- }
- }
- fclose(fpWrite);
- }
- int main()
- {
- FILE *fp;
- char str[30];
- int i;
- fp = fopen("c://score1.txt","r");
- while(fscanf(fp,"%s",str)!=EOF)
- {
- asciiDecode(str);
- }
- printf("\n\nAfter Reverse: ");
- reverseCode();
- fclose(fp);
- scanf(" ");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement