和书上结果不一样,帮忙看一下

软件和网站开发以及相关技术探讨
回复
vitamin
帖子: 247
注册时间: 2008-09-23 21:13

和书上结果不一样,帮忙看一下

#1

帖子 vitamin » 2008-10-23 11:30

和书上不一样 break 8 却停在了10
而且好像并没有执行第二次赋值,帮忙看一下问题在哪吧。 :em06
ellawu@ellawu-desktop:~$ gdb p3.4.debug
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) list
warning: Source file is more recent than executable.
1 #include <stdio.h>
2
3 int main(void){
4 char input;
5
6 int i;
7 for(i=0;i<2;i++){
8 printf("please input a character :\n");
9 scanf("%c",&input);
10
(gdb) list
11 switch(input){
12 case 'a':
13 printf("you input the character 'a'\n");
14 case 'b':
15 printf("you input the character 'b'\n");
16 case 'c':
17 printf("you input the character 'c'\n");
18 case 'd':
19 printf("you input the character 'd'\n");
20 default:
(gdb) list
21 printf("what you input is not belong to the judgement of the program\n");
22 }
23 }
24 return 0;
25 }
26
(gdb) list
Line number 27 out of range; p3.4.c has 26 lines.
(gdb) list
Line number 27 out of range; p3.4.c has 26 lines.
(gdb) break 8
Breakpoint 1 at 0x80483b5: file p3.4.c, line 8.
(gdb) break 13
Breakpoint 2 at 0x80483e0: file p3.4.c, line 13.
(gdb) run
Starting program: /home/ellawu/p3.4.debug

Breakpoint 1, main () at p3.4.c:10
10
(gdb) next
11 switch(input){
(gdb) watch input
Hardware watchpoint 3: input
(gdb) next
please input a character :
12 case 'a':
(gdb) next
af
Hardware watchpoint 3: input

Old value = -73 '�'
New value = 97 'a'
0xb7ea7301 in _IO_vfscanf () from /lib/tls/i686/cmov/libc.so.6
(gdb) next
Single stepping until exit from function _IO_vfscanf,
which has no line number information.
0xb7eb0d2b in scanf () from /lib/tls/i686/cmov/libc.so.6
(gdb) next
Single stepping until exit from function scanf,
which has no line number information.
Hardware watchpoint 3 deleted because the program has left the block
in which its expression is valid.

Breakpoint 2, main () at p3.4.c:17
17 printf("you input the character 'c'\n");
(gdb) next
19 printf("you input the character 'd'\n");
(gdb) next
you input the character 'a'
21 printf("what you input is not belong to the judgement of the program\n");
(gdb) next
you input the character 'b'
23 }
(gdb) next
you input the character 'c'
25 }
(gdb) next
you input the character 'd'
Line number 27 out of range; p3.4.c has 26 lines.
(gdb) next
what you input is not belong to the judgement of the program
10
(gdb) next
11 switch(input){
(gdb) next
please input a character :
12 case 'a':
(gdb) next

Breakpoint 2, main () at p3.4.c:17
17 printf("you input the character 'c'\n");
(gdb) next
Line number 27 out of range; p3.4.c has 26 lines.
(gdb) next
what you input is not belong to the judgement of the program
10
(gdb) next
Line number 30 out of range; p3.4.c has 26 lines.
(gdb) next
Line number 31 out of range; p3.4.c has 26 lines.
(gdb) next
0xb7e6f450 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6
(gdb) next
Single stepping until exit from function __libc_start_main,
which has no line number information.

Program exited normally.
(gdb) next
The program is not being run.
(gdb)
念几句佛经就以为自己在悟道,引用几句圣经就以为自己是上帝的使者。
躲在阴暗的角落就以为看不见你那肮脏的灵魂?
游走在灰色领域就以为安然无恙?
举头三尺有神明,不是不报是时候未到。
vitamin
帖子: 247
注册时间: 2008-09-23 21:13

Re: 和书上结果不一样,帮忙看一下

#2

帖子 vitamin » 2008-10-23 14:57

书上在第9句 scanf("%c",&input);
就要求input,可是我的要去到 12 case 'a'才要求input
是什么原因呢,是因为缺少了空格,或是哪里错了呢?
念几句佛经就以为自己在悟道,引用几句圣经就以为自己是上帝的使者。
躲在阴暗的角落就以为看不见你那肮脏的灵魂?
游走在灰色领域就以为安然无恙?
举头三尺有神明,不是不报是时候未到。
vitamin
帖子: 247
注册时间: 2008-09-23 21:13

Re: 和书上结果不一样,帮忙看一下

#3

帖子 vitamin » 2008-10-23 16:59

不告诉我,没啥了不起,我自己找到原因了。 :em24
念几句佛经就以为自己在悟道,引用几句圣经就以为自己是上帝的使者。
躲在阴暗的角落就以为看不见你那肮脏的灵魂?
游走在灰色领域就以为安然无恙?
举头三尺有神明,不是不报是时候未到。
回复