Question
Hii i have com so far in a program im trying to make : #include #include #include struct stu { float p; //personal-number char x[40];
Hii i have com so far in a program im trying to make :
#include
struct stu { float p; //personal-number char x[40]; //the name char g[6]; //gender char s[30]; //studyprogram int a; //the age char e[40]; //the email
}; struct stu *ptr;
int main(int n) { printf(" chose a num "); scanf("%d", &n); switch(n) { case 1: data (); break; case 2: modify (); break; } } int data(int n, struct stu *ptr, int i) { printf(" The number of studens you want to add? "); scanf("%d", &n); ptr = (struct stu*)malloc(n*sizeof(struct stu)); for(i = 0; i < n; i++) { printf(" Enter the personal number "); scanf("%f", &(ptr + i)->p); printf(" Enter the name of the student: "); scanf("%s", &(ptr + i)->x); printf(" the gender of the student: "); scanf("%s", &(ptr+i)->g); printf(" which program: "); scanf("%s", &(ptr+i)->s); printf(" the age of the student: "); scanf("%d", &(ptr+i)->a); printf(" The students email: "); scanf("%s", &(ptr+i)->e); //fwrite(ptr[i], sizeof(struct stu),1, fp); } printf(" The student information "); for(i = 0; i < n; ++i) printf("%f %s %s %s %d %s ", (ptr + i)->p, (ptr + i)->x, (ptr + i)->g, (ptr + i)->s, (ptr + i)->a, (ptr + i)->e); }
int modify () { struct stu s1; int pnum;
}
the thing im struggling with is that when i insert the personalnumber it dosent show right when it printed and the biggest problem is the modify function im trying to make. i want it to work like the following: The program asks for a personal number. Then the program searches the database for the student with the given personal number. If there exists such a student in the database the program asks for new information (name, gender, study program, age, and email) and replaces the new information with the old information. If the student does not exist in the database, a message has to be shown.
can you please solve it and just put some comments in the code refering to what does what. thanks in forehand!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started