segmentation fault while trying to search
hello i am getting a segmentation fault right after i ask for the social security number in the print statement. i am not sure if the fault is in the search or recsearch function. please someone help
Code:
int srch (STUDENT student[], char* ssn)
{
char* Name = "";
int tempstu = -1;
while (strcmp(ssn, "q"))
{
printf("\n Please enter social security number (press q to quit): ");
scanf("%s", ssn);
tempstu = recSrch(student, ssn, 0, SIZE - 1);
printf("\nRecord found at index %d:", tempstu);
strcat(strcat(strcpy(Name, student[tempstu].fName), " "),
student[tempstu].lName);
printf("\n%30s %9d %13s %02d/%02d/%4d", Name,
student[tempstu].grade, student[tempstu].ssn,
student[tempstu].bDate.month, student[tempstu].bDate.date,
student[tempstu].bDate.year);
}}
/*===============================recSrch=====================================*/
// this function searches for the input social security number and returns
// the result
int recSrch (STUDENT student[], char* ssn, int lb, int ub)
{
int result;
int mid = (lb + ub) / 2;
if (lb > ub)
{
result = -1;
}
else if (strcmp(ssn, student[mid].ssn) == 0)
{
result = mid;
}
else if (strcmp(ssn, student[mid].ssn) < 0)
{
result = recSrch(student, ssn, lb, mid - 1);
}
else
{
result = recSrch(student, ssn, mid + 1, ub);
}
return result;
}