|

楼主 |
发表于 2005-1-16 02:49:03
|
显示全部楼层
第一次用GDB用的不好,请大家谅解
- [root@localhost c]# gdb a2c
- GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
- Copyright 2003 Free Software Foundation, Inc.
- GDB is free software, covered by the GNU General Public License, and you are
- welcome to change it and/or distribute copies of it under certain conditions.
- Type "show copying" to see the conditions.
- There is absolutely no warranty for GDB. Type "show warranty" for details.
- This GDB was configured as "i386-redhat-linux-gnu"...
- (gdb) l
- 1 #include <stdio.h>
- 2 main()
- 3 {
- 4 double x,y;
- 5 char *ch[]={"零","一","二","三","四","五","六","七","八","九"};
- 6 char *ch1[]={"万","千","百","十"};
- 7 char num[3][4];
- 8 char snum[2];
- 9 long i,n,o,y1;
- 10 printf("input:");
- (gdb) l
- 11 scanf("%f",&x);
- 12 n=(long)x;
- 13 y=x-n;
- 14
- 15 for(i=0;i!=3;i++)
- 16 {for(o=0;o!=4;o++)
- 17 {
- 18 num[i][o]=(char)(n%10);
- 19 n/=10;
- 20 }
- (gdb) break 11
- Breakpoint 1 at 0x80483b0: file a2c2.c, line 11.
- (gdb) break 12
- Breakpoint 2 at 0x80483c4: file a2c2.c, line 12.
- (gdb) break 13
- Breakpoint 3 at 0x80483ef: file a2c2.c, line 13.
- (gdb) break 18
- Breakpoint 4 at 0x8048421: file a2c2.c, line 18.
- (gdb) l
- 21 }
- 22 y=y*100+0.5;
- 23
- 24 y1=(long)y;
- 25 for(i=0;y1!=0;i++)
- 26 {snum[i]=(char)(y1%10);
- 27 y1=y1/10;}
- 28
- 29 for(i=2;i>=0;i--){
- 30 for(o=3;o>=0;o--){
- (gdb) break 24
- Breakpoint 5 at 0x804848d: file a2c2.c, line 24.
- (gdb) l
- 31 if((int)num[i][o]>1 && (int)num[i][o]<9)
- 32 {printf("%s",ch[(int)num[i][o]]);
- 33 printf("%s",ch1[o-1]);
- 34 }
- 35 else if((int)num[i][o-1]==0)
- 36 ;
- 37 else printf("0");
- 38 if(i==0) printf("yi");
- 39 else if(i==1) printf("wan");
- 40 else if(i==2) printf("yuan");
- (gdb) break 32
- Breakpoint 6 at 0x8048564: file a2c2.c, line 32.
- (gdb) break 33
- Breakpoint 7 at 0x804858f: file a2c2.c, line 33.
- (gdb) l
- 41 }
- 42 }
- 43
- 44 if((int)snum[0]+(int)snum[1]>0)
- 45 {
- 46 if(snum[0]>0) printf("%sjiao",ch[(int)snum[0]]);
- 47 else printf("0");
- 48 if(snum[1]>0) printf("%sfen",ch[(int)snum[1]]);
- 49 }
- 50 }
- (gdb) r [color=DarkRed]前面我设置好了断点,地址是我以为出错的地方[/color]
- Starting program: /home/c/a2c
- Breakpoint 1, main () at a2c2.c:11
- 11 scanf("%f",&x);
- (gdb) n
- input:12345 [color=DarkRed]输入数字[/color]
- Breakpoint 2, main () at a2c2.c:12
- 12 n=(long)x;
- (gdb) p x [color=DarkRed]在这我发现X值不对亚[/color]
- $1 = 4.8527425639341028e-270
- (gdb) p n [color=DarkRed]N也不对亚[/color]
- $2 = 869
- (gdb) n
- Breakpoint 3, main () at a2c2.c:13
- 13 y=x-n;
- (gdb) p y [color=DarkRed]在这我发现什么值都不对[/color]
- $3 = 20443369604.764618
- (gdb) n
- 15 for(i=0;i!=3;i++)
- (gdb) n
- 16 {for(o=0;o!=4;o++)
- (gdb) n
- Breakpoint 4, main () at a2c2.c:18
- 18 num[i][o]=(char)(n%10);
- (gdb) p num [color=DarkRed]我查看NUM数组,里面全国是乱骂[/color]
- $4 = {"\024\n\023B", "柱??, "ろ??}
- (gdb) l
- 13 y=x-n;
- 14
- 15 for(i=0;i!=3;i++)
- 16 {for(o=0;o!=4;o++)
- 17 {
- 18 num[i][o]=(char)(n%10);
- 19 n/=10;
- 20 }
- 21 }
- 22 y=y*100+0.5;
- (gdb) n
- 19 n/=10;
- (gdb) p n
- $5 = 0
- (gdb) n
- 16 {for(o=0;o!=4;o++)
- (gdb) n
- Breakpoint 4, main () at a2c2.c:18
- 18 num[i][o]=(char)(n%10);
- (gdb) quit [color=DarkRed]没勇气再看了[/color]
- The program is running. Exit anyway? (y or n) y
复制代码 |
|