Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

how do you search a string from a file using file i/o?

confusedlilkidconfusedlilkid Posts: 7Member
this is what i have so far... i don't know how to begin my code for the "search" part.

[code]
int main(void)
{
int i;
student_t eee11[20];
int a=0;
int check1=0;
int check2=0;
FILE *in_file;


while(a!=1||a!=2||a!=3||a!=4){
printf("
[1] Load file
[2] Compute individual average
[3] Compute class average
[4] Exit
[5] Search for a Student
Select a number:");
scanf("%d",&a);
getchar();

switch(a){
case 1:
in_file=fopen("input_corrected.csv", "r");
if(in_file==NULL){
return 1;
}
else{
for (i=0; i<20; i++)
{
eee11[i] = get_student(in_file);
}
}
check1=1;
break;


case 2:
if(check1!=1){
printf("INVALID INPUT!");
break;
}
for (i=0; i<20; i++)
{
eee11[i].average = get_ave(eee11[i]);
printf("The average of %s is %0.2f.
", eee11[i].std_no, eee11[i].average);
printf("press enter to proceed...");
getchar();
}
check2=1;
break;


case 3:
if(check1!=1){
printf("INVALID INPUT!");
break;
}
get_class_ave(eee11, 20);
break;

case 4:
return 0;
fclose(in_file);

case 5:
//insert search code here

default:
printf("Invalid input!
");
a=0;
}
}
}
[/code]
Sign In or Register to comment.