Hi guys look at the code given below. It is from my class work. It is a simple demonstration of a singly linked list.
#include <stdio.h>
#include <stdlib.h>
#include <wctype.h>
#include <errno.h>
#include <assert.h>
#include <ctype.h>
#include <stddef.h>
#include <wchar.h>
#include <locale.h>
#include <setjmp.h>
struct node
{
int info;
struct node *link;
};
typedef struct node* NODE;
NODE main()
{
NODE first = NULL;
int item, choice;
for(;;)
{
printf("1.INSERT AT FRONT\n2.DISPLAY\n3.QUIT\n\nPLEASE ENTER YOUR CHOICE:");
scanf("%d",&choice);
switch (choice)
{
case 1:
printf("\nEnter the item to be inserted:");
scanf("%d", &item);
first = insert_front(item,first);
break;
case 2:
display(first);
break;
case 3:
exit(0);
}
}
}
NODE getnode()
{
NODE x;
x = (NODE) malloc(sizeof(struct node));
if(x == NULL)
{
printf("Out of memory");
exit(0);
}
return x;
}
int insert_front(int item, NODE first)
{
NODE temp;
temp = getnode();
temp->info = item;
temp->link = first;
return temp;
}
void display(NODE first)
{
NODE temp;
if(first == NULL)
{
printf("Empty");
return;
}
printf("\nThe contents are: ");
temp = first;
while(temp != NULL)
{
printf("%d ", temp->info);
temp = temp->link;
}
printf("\n");
}
As you can see this code demonstrates the working of a linked list. I wanna ask this question to all those hardcore C programmers that how to make this program more smaller, better, more professional and much more good. If you were given a chance to modify this program how would you do. I wanna know how to think and how to train myself to modify programs like these. And as you see I have learn't Most of C. I referred to and learn't C from K.N Kings "The C programming language: A modern approach" and "Computer science: A structured approach using C" and Data structures from "Data structures using C" by Tenenbaum.
Now I have stretched my legs in learning C what can I do to create application that might be useful to me or to others. Say I want to create a small game like "snake" or create a small application that my father might use to do his buisness. something like that. Were to go from here. How to get better at cod