Question: Write a C program so that a user can enter first and last name of students. Generate email address and identification number of the students.

Write a C program so that a user can enter first and last name of students. Generate email address and identification number of the students. Search by last name and if a match is found display the email address and identification number of the student in the console. Use a function enter() to take the information from the user and generate email address and identification number. Use a search() function to search for the student. Note: strcmp() in string.h can compare between two string. Update program with delete and sorting(insert) capabilities.

#include #include #include

typedef struct student { char first_name[30]; char last_name [30]; char email [50]; int id; } student;

student *enter()

{ int i; student *students = (student *) malloc(3 * sizeof(student)); char domain[] = "@miners.utep.edu"; for(i = 0; i < 3; ++i) { printf("Enter student %d details ", i+1); printf("First name: "); scanf("%s", students[i].first_name); printf("Last name: "); scanf("%s", students[i].last_name); students[i].email[0] = 0; strcat(students[i].email, students[i].first_name); strcat(students[i].email, students[i].last_name); strcat(students[i].email, domain); students[i].id = i + 1; } return students; }

void search(student *students) { char name[30]; int i; printf(" Enter last name to search: "); scanf("%s", name); for(i = 0; i < 3; ++i) { if(strcmp(students[i].last_name, name) ==0) { printf("First name: %s ", students[i].first_name); printf("Email: %s ", students[i].email); printf("ID: %d ", students[i].id);

} } }

int main() { student *students = enter(); search(students); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!