当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 3 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : 和书上结果不一样,帮忙看一下
帖子发表于 : 2008-10-23 11:30 

注册: 2008-09-23 21:13
帖子: 247
送出感谢: 0 次
接收感谢: 0 次
和书上不一样 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)


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


页首
 用户资料  
 
2 楼 
 文章标题 : Re: 和书上结果不一样,帮忙看一下
帖子发表于 : 2008-10-23 14:57 

注册: 2008-09-23 21:13
帖子: 247
送出感谢: 0 次
接收感谢: 0 次
书上在第9句 scanf("%c",&input);
就要求input,可是我的要去到 12 case 'a'才要求input
是什么原因呢,是因为缺少了空格,或是哪里错了呢?


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


页首
 用户资料  
 
3 楼 
 文章标题 : Re: 和书上结果不一样,帮忙看一下
帖子发表于 : 2008-10-23 16:59 

注册: 2008-09-23 21:13
帖子: 247
送出感谢: 0 次
接收感谢: 0 次
不告诉我,没啥了不起,我自己找到原因了。 :em24


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


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 3 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:Google Feedfetcher 和 1 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译