- UID
 - 70863
 
 注册时间2010-12-2
阅读权限30
最后登录1970-1-1
龙战于野 
  
 
 
 
TA的每日心情  | 开心 2015-12-28 01:47 | 
|---|
 
  签到天数: 3 天 [LV.2]偶尔看看I  
 | 
 
 本帖最后由 LShang 于 2010-12-31 16:38 编辑  
 
写这段代码用了将近4个小时的时间,本以为应该可以顺利完成的. 
但是试运行是总是会出错,改了将近3个小时了,实在是头大. 
现在脑袋嗡嗡的,一点思路都没有了... 
所以把源码贴出来同学们帮我看下,到底是哪里出的问题. 
bug为选择B功能,输入字符串时,回车后字符串消失.并且不执行下边代码.- main()
 
 - {
 
 -         unsigned char a[99]={0};
 
 -         char b[99]={0};
 
 -         char * c = "A.Encrypted String.";
 
 -         char * d = "B.Decryption Key.";
 
 -         int i ;
 
 -         int j ;
 
 -         while(*a != 'c')
 
 -         {
 
 -                 clrscr();
 
 -                 printf("String encryption or decryption.     By: LShang\n");
 
 -                 printf("Please select the function:\n");
 
 -                 printf("A.Encrypted String.\n");
 
 -                 printf("B.Decryption Key.\n");
 
 -                 printf("C.Exit.\n");
 
 -                 scanf(" %c",a);
 
 -                 if(*a == 'a')
 
 -                 {
 
 -                         i = 0;
 
 -                         while(i>=0)
 
 -                         {
 
 -                                 clrscr();
 
 -                                 printf("The current selection:");
 
 -                                 printf("%s\n",c);
 
 -                                 printf("Please enter a string.\n");
 
 -                                 printf("String:");
 
 -                                 scanf("%99s",a);
 
 -                                 while(*(a+i))
 
 -                                 {               
 
 -                                         i++;
 
 -                                 }
 
 -                                 i--;
 
 -                                 printf("Encrypted String:");
 
 -                                 while(i>=0)
 
 -                                 {       
 
 -                                         printf("%X",*(a+i));
 
 -                                         i--;
 
 -                                 }
 
 -                         }
 
 -                         printf("\nPress 'q' return to the main menu.%c",8);
 
 -                         *a = getch();
 
 -                 }else if(*a == 'b')
 
 -                 {
 
 -                         i = 0;
 
 -                         j = 0;
 
 -                         while(i>=0)
 
 -                         {
 
 -                                 clrscr();
 
 -                                 printf("The current selection:");
 
 -                                 printf("%s\n",d);
 
 -                                 printf("Please enter the key.\n");
 
 -                                 printf("Key:");
 
 -                                 scanf("%99s",a);
 
 -                                 while(*(a+i))
 
 -                                 {
 
 -                                         i++;
 
 -                                 }
 
 -                                 for(j=0;j<i;j++)
 
 -                                 {
 
 -                                         if((*(a+j)>='0') && (*(a+j)<='9'))
 
 -                                         {
 
 -                                                 *(a+j) -= 0x30;
 
 -                                         }else if((*(a+j)>='a') && (*(a+j)<='f'))
 
 -                                         {
 
 -                                                 *(a+j) -= 0x57;
 
 -                                         }else if((*(a+j)>='A') && (*(a+j)<='F'))
 
 -                                         {
 
 -                                                 *(a+j) -= 0x37;
 
 -                                         }else
 
 -                                         {
 
 -                                                 printf("Error");
 
 -                                         }
 
 -                                 }
 
 -                                 i--;
 
 -                                 printf("Decrypted string:");
 
 -                                 for(j=i;j>=0;j--)
 
 -                                 {
 
 -                                         if(!(j%2) && i>=0)
 
 -                                         {
 
 -                                                 *(b+i)=(*(a+j)*0x10)+*(a+j+1);
 
 -                                                 printf("%c",*(b+i));
 
 -                                                 i--;
 
 -                                         }
 
 -                                 }
 
 -                         }
 
 -                         printf("\nPress 'q' return to the main menu.%c",8);
 
 -                         *a = getch();
 
 -                 }
 
 -                 clrscr();
 
 -         }
 
 - }
 
 
  复制代码 大家帮我看看,是逻辑错误还是什么?为什么编译时候没问题... |   
 
 
 
 |