I'm using codeblocks and I defined a string array..
Code:
char *sname[10]; /* array for student name */
I loaded the array..
Code:
for ( x = 0; x < ngo; x++ ) // gets info*/
{
printf( "\nPlease enter the student name %d ", x);
scanf("%s", &name);
sname[x] = name;
printf( "\nPlease enter the student gpa %d ", x);
scanf("%d", &sgpa);
gpa[x] = sgpa;
}
and then if I try to access it while sorting
Code:
printf("\n got here to name swap = %d %d %s ", i, j, sname[i]);
holdname = sname[i]; /* swap the name */
sname[i] = sname[j];
sname[j] = holdname;
It fails and gives 'Segmentation fault."
It is NOT the integer (it's well inside the boundary for the 10, but if I try to even
printf, as above, the string array name it blows.Even if I put zero.
Any idea why?
Thanks,
Deaf