store your name, ID, SSC Grade, HSC Grade using linked list and display it.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// The structure to hold the linked list node
typedef struct Node Node;
typedef struct Node {
char text[30];
Node* next;
} Node;
int main()
{
// Allocating memory
Node* name = (Node *) malloc(sizeof(Node));
name->next = (Node *) malloc(sizeof(Node));
name->next->next = (Node *) malloc(sizeof(Node));
name->next->next->next = (Node *) malloc(sizeof(Node));
// Store my name, ID, SSC Grade, HSC Grade using the linked list
strcpy(name->text, "name");
strcpy(name->next->text, "id");
strcpy(name->next->next->text, "SSC grade");
strcpy(name->next->next->next->text, "HSC grade");
// Displaying my name, ID, SSC Grade, HSC Grade using the linked list
printf("My name: %s\n", name->text);
printf("ID: %s\n", name->next->text);
printf("SSC grade: %s\n", name->next->next->text);
printf("HSC grade: %s\n", name->next->next->next->text);
// Freeing the allocated memory
free(name->next->next->next);
free(name->next->next);
free(name->next);
free(name);
return 0;
}
Comments
Leave a comment