C exercises and solutions: update record

C structure: update record

Step 7: Defining the update_reg(student st[], int itemcount) function to update a specified record. The update process starts by asking the user to input the id of the record to be changed. The id value is checked to make sure it really exists. If it exists the change to the target record can be made after asking the user to input the new value of the field that need change.

//function to update record
void update_rec(student st[],int itemcount){
char id[10];
int column_index;
printf("Enter student's ID:");
printf("Which field you want to update(1-7)?:");

int index = search(st, id,itemcount);

if (index != -1)
if (column_index == 1)
printf("Enter student's Name:");


else if (column_index == 2)
printf("Enter student's Sex(F or M):");
else if (column_index == 3)
printf("Enter student's quizz1 score:");
else if (column_index == 4)
printf("Enter student's quizz2 score:");
else if (column_index == 5)
printf("Enter student's assigment score:");
else if (column_index == 6)
printf("Enter student's mid term score:");
else if (column_index == 7)
printf("Enter student's final score:");
else printf("Invalid column index");

st[index].total = st[index].quizz1 + st[index].quizz2 + st[index].assigment + st[index].midterm + st[index].final;

else printf("The record deosn't exits.Check the ID and try again.");



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.