Hi, there.
Today I use gdb to debug my homework but I meet troubles.
it's a program that get two arrays and then sort them and merge them then output them.
this is the trouble:
how can I see the value in array a?Code:(gdb) b main
Breakpoint 1 at 0x4014af: file 9_14.c, line 43.
(gdb) r
Starting program: 1.exe
Breakpoint 1, main () at 9_14.c:43
43 int main(void){
(gdb) n
44 int const m = 5, n = 6;
(gdb) n
45 int a[m], b[n], c[m + n];
(gdb) n
46 get (a, m, b, n);
(gdb) p a
No symbol "a" in current context.
(gdb) n
47 sort(a, m);
(gdb) p a
No symbol "a" in current context.
(gdb)
Thank you.
this is the source code:
(I have finished the debuging. but the question still exists)
Code:#include <stdio.h>
void get(int a[], int m, int b[], int n){
int i;
for(i = 0; i < m; i++)
scanf("%d", &a[i]);
for(i = 0; i < n; i++)
scanf("%d", &b[i]);
}
void sort(int a[], int m){
int i, j, t;
for(i = 0; i < m; i++)
for(j = m - 1; j > i; j--){
if (a[j] < a[j - 1]){
t = a[j];
a[j] = a[j - 1];
a[j - 1] = t;
}
}
}
void merge(int a[], int m, int b[], int n, int c[]){
int ap = 0, bp = 0, cp = 0;
while(ap < m && bp < n){
if (a[ap] > b[bp])
c[cp++] = b[bp++];
else
c[cp++] = a[ap++];
}
if(ap < m)
memcpy(&c[cp], &a[ap], (m - 1 - ap) * sizeof(int));
if(bp < m)
memcpy(&c[cp], &a[bp], (n - 1 - bp) * sizeof(int));
}
void pr(int a[], int n){
int i;
for(i = 0; i < n; i++)
printf("%d\t", a[i]);
}
int main(void){
int const m = 5, n = 6;
int a[m], b[n], c[m + n];
get (a, m, b, n);
sort(a, m);
sort(b, n);
merge(a, m, b, n, c);
pr(c, m + n);
return(0);
}