C exercises and solutions: C structure add new record to list

C structure: add new record to list

Step 3: Defining the add_rec(student[] st, int *itemcount) function to add a new record to the the array of student objects. This function takes two arguments. The first argument is the array of student objects(st) and the second argument is the number of items in the array. This function firstly checks the new record(using the search function that is defined in the next step) before it is allowed to be appended to the array to avoid duplicate records. When the new item is added the value of itemcount variable increases by 1 that means the number of records in the list increases.

//function to append a new record
void add_rec(student st[],int *itemcount){

  printf("\nEnter student's ID:");
  printf("This ID already exists\n");goto again;

  printf("Enter student's Name:");
  printf("Enter student's Sex(F or M):");scanf("%s",&st[*itemcount].sex);
  printf("Enter student's quizz1 score:");scanf("%f",&st[*itemcount].quizz1);
  printf("Enter student's quizz2 score:");scanf("%f",&st[*itemcount].quizz2);
  printf("Enter student's assigment score:");scanf("%f",&st[*itemcount].assigment);
  printf("Enter student's mid term score:");scanf("%f",&st[*itemcount].midterm);
  printf("Enter student's final score:");scanf("%f",&st[*itemcount].final);
  st[*itemcount].total=st[*itemcount].quizz1+st[*itemcount].quizz2+st[*itemcount].assigment+st[*itemcount].midterm+st [*itemcount].final;




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.