Question: I need help with this problem: Write a program that inputs a line of text and uses a stack to print the line reversed. I
I need help with this problem:
Write a program that inputs a line of text and uses a stack to print the line reversed.
I am trying to get this program to work but I keep getting an error "a value of type "void*" cannot be assigned to an entity of type "RevLine*":
This is the code I'm trying to execute:
#include
struct revLine { char lineTokken[20]; struct revLine *next; }; typedef struct revLine RevLine;
revLine* popStack(RevLine *); revLine* pushStack(RevLine*, char *);
int main() { char sentence[80]; char tokken[80]; int length, loop; int insPosition;
RevLine *stackHead; stackHead = NULL;
printf("Enter a sentence"); scanf("%s",sentence); strcat(sentence, " "); length = strlen(sentence); insPosition = 0;
for (loop = 0; loop < length; loop++) { if (sentence[loop] != ' ') { tokken[insPosition++] = sentence[loop]; }
else { tokken[insPosition] = '\0'; stackHead = pushStack(stackHead, tokken);
insPosition = 0; }
}
stackHead = popStack(stackHead);
return(0); }
RevLine *pushStack(RevLine *headStack, char *word) { RevLine *newNode; newNode = malloc(sizeof(RevLine)); strcpy(newNode->lineTokken, word); newNode->next = headStack; headStack = newNode; return(headStack); }
RevLine* popStack(RevLine *headStack) { RevLine *delNode; int counter = 0;
printf("Output is : ");
while (headStack != NULL) { delNode = headStack; printf("Counter = %d and element popped is: %s ", ++counter, delNode->lineTokken); headStack = headStack->next; free(delNode); } return(headStack); }
Where am I going wrong?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
