no errors and warnings...but dowanna accaept input... ...and i'm totally confused..can someone help me repair this codes...
Code:
#include <stdio.h>
#include <stdlib.h>
struct stackNode {
char data;
struct stackNode *nextPtr;
};
typedef struct stackNode StackNode;
typedef StackNode *StackNodePtr;
void push( StackNodePtr *, int );
int pop( StackNodePtr * );
int isEmpty( StackNodePtr );
void printStack( StackNodePtr );
void instructions( void );
int main()
{
StackNodePtr stackPtr = NULL;
int choice;
char value[20];
instructions();
printf( "? " );
scanf( "%d", &choice );
while ( choice != 3 ) {
switch ( choice ) {
case 1:
printf( "Enter a student name: " );
fflush(stdin);
gets(value );
printStack( stackPtr );
break;
case 2:
if ( !isEmpty( stackPtr ) )
printf( "The deleted name is %s.\n",
pop( &stackPtr ) );
printStack( stackPtr );
break;
default:
printf( "Invalid choice.\n\n" );
instructions();
break;
}
printf( "? " );
scanf( "%d", &choice );
}
printf( "End of run.\n" );
return 0;
}
void instructions( void )
{
printf( "Enter choice:\n"
"1 to enter a student name stack\n"
"2 to delete a student name stack\n"
"3 to end program\n" );
}
void push( StackNodePtr *head, int info )
{
StackNodePtr newPtr;
newPtr = malloc( sizeof( StackNode ) );
if ( newPtr != NULL ) {
newPtr->data = info;
newPtr->nextPtr = *head;
*head = newPtr;
}
else
printf( "%d not inserted. No memory available.\n",
info );
}
int pop( StackNodePtr *head )
{
StackNodePtr tempPtr;
int popValue;
tempPtr = *head;
popValue = ( *head )->data;
*head = ( *head )->nextPtr;
free( tempPtr );
return popValue;
}
void printStack( StackNodePtr currentPtr )
{
if ( currentPtr == NULL )
printf( "The stack is empty.\n\n" );
else {
printf( "The stack is:\n" );
while ( currentPtr != NULL ) {
printf( "%s --> ", currentPtr->data );
currentPtr = currentPtr->nextPtr;
}
printf( "NULL\n\n" );
}
}
int isEmpty( StackNodePtr topPtr )
{
return topPtr == NULL;
}