-
Notifications
You must be signed in to change notification settings - Fork 1
/
student_array
61 lines (55 loc) · 1.55 KB
/
student_array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
struct name{
char fname[20];
char lname[20];
};
struct record{
int sem, phone;
float CGPA;
char email[100], branch[50];
struct name name[2];
}*ptr;
ptr=(struct record*) malloc(10*sizeof(struct record));
int i;
char s[20];
for(i=0; i<10; i++){
printf("Enter details of student %d\n", i+1);
printf("Enter the first name: \n");
scanf("%s", &(ptr+i)->name[i].fname);
printf("Enter the last name: \n");
scanf("%s", &(ptr+i)->name[i].lname);
printf("Enter branch: \n");
scanf("%s", &(ptr+i)->branch);
printf("Enter semester: \n");
scanf("%d", &(ptr+i)->sem);
printf("Enter e-mail: \n");
scanf("%s", &(ptr+i)->email);
printf("Enter phone number: \n");
scanf("%d", &(ptr+i)->phone);
printf("Enter the CGPA: \n");
scanf("%f", &(ptr+i)->CGPA);
}
printf("\n");
printf("Enter the First Name of the student whose details need to be seen: \n");
scanf("%s", &s);
int found=0;
for(i=0; i<10; i++){
if(strcmp(s, (ptr+i)->name[i].fname)==0){
printf("Displaying student information:\n");
printf("Full Name: %s %s\n", (ptr+i)->name[i].fname, (ptr+i)->name[i].lname);
printf("Branch: %s\n", (ptr+i)->branch);
printf("Semester: %d\n", (ptr+i)->sem);
printf("CGPA: %.2f\n", (ptr+i)->CGPA);
printf("Email: %s\n", (ptr+i)->email);
printf("Phone Number: %d\n", (ptr+i)->phone);
found=1;
}
}
if(found==0)
printf("Student is not present in the list");
return 0;
}