Lab Program 7 (1)
Lab Program 7 (1)
Develop a menu driven Program in C for the following operations on Singly Linked List
(SLL) of Student Data with the fields: USN, Name, Programme, Sem, PhNo
e. Exit
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
char USN[20];
char Name[50];
char Programme[20];
int Sem;
char PhNo[15];
};
struct Student *createStudent(char USN[], char Name[], char Programme[], int Sem, char PhNo[]) {
1
if (newStudent == NULL) {
exit(1);
strcpy(newStudent->USN, USN);
strcpy(newStudent->Name, Name);
strcpy(newStudent->Programme, Programme);
newStudent->Sem = Sem;
strcpy(newStudent->PhNo, PhNo);
newStudent->next = NULL;
return newStudent;
newStudent->next = head;
return newStudent;
if (head == NULL) {
return newStudent;
2
struct Student *current = head;
current = current->next;
current->next = newStudent;
return head;
if (head == NULL) {
return head;
head = head->next;
free(temp);
return head;
// Function to display the linked list and count the number of nodes
3
int count = 0;
printf("Student Data:\n");
printf("-------------------------------------------------------------------------------------------\n");
printf("-------------------------------------------------------------------------------------------\n");
current = current->next;
count++;
int main() {
int choice;
while (1) {
4
printf("4. Delete from Front (Stack demonstration)\n");
printf("6. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1: {
int Sem;
scanf("%s", USN);
scanf("%s", Name);
scanf("%s", Programme);
scanf("%d", &Sem);
scanf("%s", PhNo);
break;
case 2: {
5
char USN[20], Name[50], Programme[20], PhNo[15];
int Sem;
scanf("%s", USN);
scanf("%s", Name);
scanf("%s", Programme);
scanf("%d", &Sem);
scanf("%s", PhNo);
break;
case 3: {
int Sem;
scanf("%s", USN);
scanf("%s", Name);
scanf("%s", Programme);
6
printf("Enter Semester: ");
scanf("%d", &Sem);
scanf("%s", PhNo);
break;
case 4:
head = deleteFront(head);
break;
case 5:
displayAndCount(head);
break;
case 6:
exit(0);
default:
return 0;
OUTPUT
7
8
9
10