Code:
#include<stdio.h>main()
{
int a,b,g,ind;
char c;
a=0;
g=0;
ind=0;
for(g=0;g<5;g++)
{
printf("insert c\n");
scanf("%c", &c);
if ( c=='1' ) {
a=a*10+ (int) (c-'0');
ind=1;
}
if (ind==1 && c!='1' )
{
printf("%d\n" ,a);
ind=0;
a=0;}
}
}
so thats my code and this is what i get from gdb
Code:
(gdb) break 1
Breakpoint 1 at 0x40065e: file kol1.c, line 1.
(gdb) run
Starting program: /home/djordje/Desktop/programiranje/kol1
Breakpoint 1, main () at kol1.c:3
3 {
(gdb) display c
1: c = 0 '\000'
(gdb) next
6 a=0;
1: c = 0 '\000'
(gdb) next
8 g=0;
1: c = 0 '\000'
(gdb) next
9 ind=0;
1: c = 0 '\000'
(gdb) next
10 for(g=0;g<5;g++)
1: c = 0 '\000'
(gdb) next
12 printf("insert c\n");
1: c = 0 '\000'
(gdb) next
insert c
13 scanf("%c", &c);
1: c = 0 '\000'
(gdb) next
1
15 if ( c=='1' ) {
1: c = 49 '1'
(gdb) next
17 a=a*10+ (int) (c-'0');
1: c = 49 '1'
(gdb) next
18 ind=1;
1: c = 49 '1'
(gdb) next
21 if (ind==1 && c!='1' )
1: c = 49 '1'
(gdb) next
10 for(g=0;g<5;g++)
1: c = 49 '1'
(gdb) next
12 printf("insert c\n");
1: c = 49 '1'
(gdb) next
insert c
13 scanf("%c", &c);
1: c = 49 '1'
(gdb) next
15 if ( c=='1' ) {
1: c = 10 '\n'
commands i used in gdb are bold, the output is standard and the red lines are where the strange thing happens so as you see after the scanf gdb doesnt let me insert my own value for c instead it assigns the default( or is it default) value to c, any help is apriciated thanks