program 1
program 1
structure shown below: USN, Student Name, and Semester. Write the necessary functions To display
all the records in the file and a function to search for a specific record based on the USN. In case the
record is not found, suitable message should be displayed. Both the options in this case must be
demonstrated.( Use pointer structure for dynamic memory allocation) .
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
char USN[15];
char name[100];
int semester;
};
printf("\nStudent Records:\n");
printf("-------------------------------------------------\n");
printf("-------------------------------------------------\n");
int found = 0;
if (strcmp(students[i].USN, usn) == 0) {
printf("\nRecord Found:\n");
printf("USN: %s\n", students[i].USN);
found = 1;
break;
if (!found) {
int main() {
int N,ch;
scanf("%d", &N);
if (students == NULL) {
return 1;
scanf("%s", students[i].USN);
scanf("%s", students[i].name);
printf("Enter Semester: ");
scanf("%d", &students[i].semester);
while(1){
printf("\n1. Display");
printf("\n2.Search");
printf("\n3.Exit");
scanf("%d",&ch);
switch(ch){
break;
scanf("%s", searchUSN);
search(students, N, searchUSN);
break;
case 3: exit(0);
free(students);
return 0;