thanks alot for the explanation guys rly helped alot!!
ive applied what u said and for a name search it is returning the correct result, however after the result is returned, then i get a segmentation fault, (my most hated fault :P), and for date, which is also a string i also get segmentation fault but no values returned correctly as with name.
the code for my Name and Date switch cases are below:
Code:
case 2 : printf("Enter search string (no spaces): \n");
scanf("%s",z);
clearscreen();
printf("Search Result : \n\n");
printf("ID Name Date Min Max Valid \n\n");
for(i=1;i<=20;i++) {
if(strcmp(record[i].Name, z) == 0) {
printf("%-4d %-20s %-10s %.3f %.3f %d\n", record[i].ID, record[i].Name, record[i].Date, record[i].Min_temp, record[i].Max_temp, record[i].Valid);
}
}
break;
case 3 : printf("Enter Date (in the form xx/xx/xx): \n");
scanf("%s",z);
clearscreen();
printf("Search Result : \n\n");
printf("ID Name Date Min Max Valid \n\n");
for(i=1;i<=20;i++) {
if(strcmp(record[i].Date, z) == 0) {
printf("%-4d %-20s %-10s %.3f %.3f %d\n", record[i].ID, record[i].Name, record[i].Date, record[i].Min_temp, record[i].Max_temp, record[i].Valid);
}
}
break;
Maybe it will help to know ive got my z variable declared like this:
and that when i compile i get the warning:
warning: 'z' might be used unitialised in this function
any ideas on fixing this would be great, and thanks for the help already