This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/42799] New: Variable unexpectedly set to 0 because a scanf()


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]