Please Help Me! Executing Problem
I already compile my C and it went well. But when it comes to execute it, it indicate error,..please help me with this,..
Code:
#include <stdio.h>
#include <stdlib.h>
struct ptr
{int data;
struct ptr *nextptr;
};
typedef struct ptr POINT;
void printList (POINT *sptr);
insert (POINT **startptr);
deduct (POINT **startptr);
void main()
{
int choice;
POINT *startptr=NULL;
printf("Please key in your choice\n\n");
printf("1.INSERT\n");
printf("2.DEDUCT\n");
printf("3.DISPLAY SCREEN\n");
printf("4.EXIT\n");
printf("INPUT : ");
scanf("%d",&choice);
while (choice!=4)
{
if (choice==1)
{
insert(&startptr);
}
else if (choice==2)
{
deduct(&startptr);
}
else if (choice==3)
{
printList(startptr);
}
printf("Please key in your choice\n\n");
printf("1.INSERT\n");
printf("2.DEDUCT\n");
printf("3.DISPLAY SCREEN\n");
printf("4.EXIT\n");
printf("INPUT : ");
scanf("%d",&choice);
}
}
insert(POINT **startptr)
{
int user_input;
char user_input2;
POINT *tptr=NULL, *nextptr=NULL, *lastptr=NULL, *newptr=NULL, *tempptr=NULL;
tptr = *startptr;
printf("Enter Input : ");
scanf("%d",&user_input);
while(user_input!=-1)
{
if (tptr==NULL)
{
tptr=(POINT *) malloc(sizeof(POINT));
tptr->data=user_input;
tptr->nextptr=NULL;
lastptr=tptr;
*startptr=tptr;
}
else
{
lastptr->nextptr = (POINT *) malloc(sizeof(POINT));
lastptr=lastptr->nextptr;
lastptr->data=user_input;
lastptr->nextptr=NULL;
}
printf("Do you want to enter another number? ");
scanf("%c",&user_input2);
if (user_input2=='Y'||user_input2=='y')
{
printf("Please enter value: ");
scanf("%d",&user_input);
}
else if (user_input=='N'||user_input2=='n')
{
user_input=-1;
}
}
return (0);
}
void printList(POINT *sptr)
{
POINT *tempptr=sptr;
while (tempptr!=NULL)
{
printf("Thank You.\n");
}
printf("NULL\n\n");
}