c - Defining a delete(student st[], int *itemcount) function to delete a target record from the array of student objects -


i'm trying learn c programming trying practices. see below search function returns 1 or -1 , variable index being used determine whether target student exists or not. after again being used determine whether last, in middle, or first item in array. how can index have numeric value when assigned returned value search function it? please me figure out. thank you.

//function delete record void delete_rec (student st[], int *itemcount) {     char id[10];     int index, i;     if (*itemcount > 0) {         printf ("enter student's id:");         scanf ("%s", id);         index = search (st, id, *itemcount);          if ((index != -1) && (*itemcount != 0)) {             if (index == (*itemcount - 1))  //delete last record             {                  clean (st, index);                 --(*itemcount);                  printf ("the record deleted.\n");             } else      //delete first or middle record             {                 (i = index; < *itemcount - 1; i++) {                     st[i] = st[i + 1];                     clean (st, *itemcount);                     --(*itemcount);                 }              }          } else             printf ("the record doesn't exist.check id , try again.\n");       } else         printf ("no record delete\n"); }  //function clean deleted record void clean (student st[], int index) {      strcpy (st[index].stnumber, "");     strcpy (st[index].stname, "");     st[index].sex = null;     st[index].quizz1 = 0;     st[index].quizz2 = 0;     st[index].assigment = 0;     st[index].midterm = 0;     st[index].final = 0;     st[index].total = 0;  } 

how can index have numeric value when assigned  returned value search function it? 

index (the value returned search()) set in search the actual loop index record string comparison between st[i].stnumber , id match:

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

that insures index has numeric value of index record in list. return search() not 1 or -1.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -