how do i want to add search funtion by matric value to get the info of the student add this code

#include <stdio.h>
#define MAX 10
struct studenInfo{
char name[81];
char matric[71];

};
int main()
{
struct studenInfo library[MAX];
int menu (void);
struct studenInfo add(void);
void list(struct studenInfo*sp, int size);
int choice, count = 0;
do
{
choice = menu();
switch(choice)
{
case 0:
puts("End of my act! :-");
break;
case 1:
if (count < MAX)
{
library[count]=add();
count++;
}
else
puts("Library is reached maximum capacity");
break;
case 2:

list (library, count);

break;

default:
puts("Wrong selection. Try again");
}
}while (choice !=0);
return 0;
}//end of main

int menu(void)
{
int choice;
puts("\n<<Super Duper Menu>>");
puts("\t0:Exit");
puts("\t1:Add Info ");
puts("\t2:List all the Info");
printf("Enter your selection");
scanf("%d", &choice);
return choice;
}
struct studenInfo add(void)
{
struct studenInfo temp;
fflush(stdin);
puts("\n<<ADD MORE>>");
printf("Enter name : ");
gets(temp.name);
printf("Enter matric number : ");
gets(temp.matric);

return temp;
}
void list(struct studenInfo * sp, int size)
{
int i;
printf("\n");
puts("<<BOOK LIST>>");
for (i=0; i<size; ++i, ++sp)
printf("%d by %s --- %s\n", i+1, sp->name, sp-> matric);
return;
}

Edited 6 Years Ago by konata_89: n/a

First you have to create another menu item, and then write a function that implements it. Just a simple linear search will do -- from the first to last items in the array.

This article has been dead for over six months. Start a new discussion instead.