This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/42799] New: Variable unexpectedly set to 0 because a scanf()
- From: "adriyetichaves at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Jan 2010 09:48:09 -0000
- Subject: [Bug c/42799] New: Variable unexpectedly set to 0 because a scanf()
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I'm learning C, so it's possible there's a reason for this, but I've made a lot
of tests to find out that in my source code a variable (called "q_num") changes
from 3 to 0 just because of a scanf().
I tested the code with these lines:
...
printf("1. %d\n",q_num);
p=scanf("%d",&idade);
printf("2. %d\n",q_num);
...
And results in:
1. 3 // Value dynamicly set before by a function
15 // Just the value entered to the scanf()
2. 0 // Value after the scanf(), expected a 3 again
I'll attach complete source code.
--
Summary: Variable unexpectedly set to 0 because a scanf()
Product: gcc
Version: 4.4.2
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: adriyetichaves at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42799