C exercises and solutions: view records in list

C structure: view records in list

Step 4: Defining the search(struct st[], char id[], int itemcount) function to search for the index of a target record. This function is useful as we need it to find the location of the target record in the array of student objects. It can help us to make sure the record does exist before we allow the record for deleting or updating. If the target element is found, the function returns the index of this element. It return -1, if the target element is not found in the array.

//function to find the location of the record
int search(student st[], char id[],int itemcount){
  int found =-1,i;

  for (i = 0; i < itemcount && found==-1; i++)

    if (strcmp(st[i].stnumber,id)==0) found=i;

    else found=-1 ;

return found;

Step 5: Defining the viewall(student st[], int itemcount) function to display the list of all records in the set. To display all records, we need a while loop to traverse through the array of student objects.

//function to view all records
void viewall(student st[], int itemcount){
 int i=0;
    printf("%-7.1f",st[i]. final);



void displayheading(){
   printf("ID NAME SEX Q1 Q2 As Mi Fi TOTAL \n");



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.