This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/36229] New: scanf does not read correctly
- From: "mkarakoc at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 May 2008 13:02:07 -0000
- Subject: [Bug c/36229] New: scanf does not read correctly
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
#include <stdio.h>
#define length 50
int main()
{
int i=0,finish=0;
char A[length];
char B[3];
printf("Input A --> ? ");
scanf("%s",A);
printf("Input B --> ? ");
scanf("%s",B);
printf("Output A --> %s (It reads first char as \'\\0\')\n",A);
printf("Output B --> %s\n",B);
printf("Output A --> ");
while(finish!=1)
{
if((i>1)&&(A[i]=='\0')) finish=1;
printf("%c",A[i],i);
i++;
}
printf(" (This is the proof!)\n");
}
hi,
i am new in C language. i tried to find what is wrong the code above.
The code runs correctly when i compiled it with gcc-3.x and 2.9x, but it does
not run when i compiled it using gcc-4.1.1 (linux debian 4.0 etch).
you could see when you input something for A and B. It reads B correctly. For
A, it reads first character as '\0'.
I find a solution to fix it from the code.
in the code:
-----------------
char A[length];
char B[3];
-------------------
if i change it as in below:
char B[3];
char A[length];
scanf runs correctly.
I am not sure it is a bug. But I thought it might be.
--
Summary: scanf does not read correctly
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mkarakoc at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36229