用while加scanf循环赋值问题
static int CreatList(Linklist *L,int n)
{
int a[]={0};
Linklist *s,*r;
int i=0;
int j=0;
r=L;
do
{
scanf("%d",&a[i]);
j=i++;
}
while(a[j]!=-1);
...
}
ubuntu下gdb调试
Breakpoint 1, main () at blinklist.c:197
197 CreatList(L,i);
(gdb) s
CreatList (L=0x804867b, n=0) at blinklist.c:54
54 int a[]={0};
(gdb) s
60 int i=0;
(gdb) x/x &a
0xbffff65c: 0x00000000
(gdb) x/8x &a
0xbffff65c: 0x00000000 0x0000003b 0xb7fee8d0 0x0000003b
0xbffff66c: 0x0028bff4 0x00000000 0x00000000 0xbffff6a8
(gdb) s
62 int j=0;
(gdb) s
65 r=L;
(gdb) s
74 scanf("%d",&a[i]);
(gdb) s
1 2 3 -1
77 j=i++;
(gdb) s
82 while(a[j]!=-1);
(gdb) print j
$1 = 0
(gdb) print i
$2 = 1
(gdb) s
74 scanf("%d",&a[i]);
(gdb) s
77 j=i++;
(gdb) x/8x &a
0xbffff65c: 0x00000001 0x00000002 0x00000000 0x00000001
0xbffff66c: 0x0804867b 0x00000000 0x00000000 0xbffff6a8
(gdb) s
82 while(a[j]!=-1);
(gdb) print j
$3 = 1
(gdb) pint i
Undefined command: "pint". Try "help".
(gdb) print i
$4 = 2
(gdb) s
74 scanf("%d",&a[i]);
(gdb) s
77 j=i++;
(gdb) x/8x &a
0xbffff65c: 0x00000001 0x00000002 0x00000003 0x00000002
0xbffff66c: 0x0804867b 0x00000000 0x00000000 0xbffff6a8
(gdb) s
82 while(a[j]!=-1);
(gdb) s
74 scanf("%d",&a[i]);
(gdb) print j
$5 = 2
(gdb) print i
$6 = 3
(gdb) s
77 j=i++;
(gdb) x/8x &a
0xbffff65c: 0x00000001 0x00000002 0x00000002 0xffffffff
0xbffff66c: 0x0804867b 0x00000000 0x00000000 0xbffff6a8
(gdb) s
82 while(a[j]!=-1);
(gdb) s
74 scanf("%d",&a[i]);
(gdb) print j
$7 = -1
(gdb) x/8x &a
0xbffff65c: 0x00000001 0x00000002 0xffffffff 0x00000000
0xbffff66c: 0x0804867b 0x00000000 0x00000000 0xbffff6a8
(gdb)
为什么j会等于-1呢?谢谢高手指点。