My professor gave me this code to work with... struct node{ char value; struct node * nPtr; //points to next node }; typedef struct node nodePtr; typedef nodePtr * listNodePtr; And to implement this function void insert(listNodePtr *ptr, char c) When I compile this in gcc, I get this prelab4.h:7: error: expected â)â before â*â token Why is it telling me this? I feel like putting a ) after the * wouldn't be good. Am I accessing it correctly? I am calling for a pointer of type listNodePtr, right?
Hmm, I'm not sure why you are getting that error, but are you sure insert should be taking listNodePtr* (which is equivalent to struct node**) instead of listNodePtr (which is struct node*) Also, you might be missing a semicolon after the void insert declaration: void insert(listNodePtr *ptr, char c); If that doesn't help, could you paste the entirety of the header to a site like pastebin or something?
I literally copied and pasted this from the prelab. I have no clue why it won't compile. I've attached out prelab form. I feel like I should brush up on some linkedlist stuff, and this should make sense, but I have no idea why they would give us bad code to begin with!!
The code below compiles. #include <stdio.h> struct node{ char value; struct node * nPtr; //points to next node }; typedef struct node nodePtr; typedef nodePtr * listNodePtr; //void insert(listNodePtr *ptr, char c) int main (int argc, char * const argv[]) { printf("hello world"); }
Join our real-time social learning platform and learn together with your friends!