I am trying to pass a string to this function:
Code:
void insert(ListNodePtr *sPtr, char *value);
I am gathering the string from scanf, printing it, and then passing it to the function like so (I am building a linked list):
Code:
struct listNode
{
char *data;
struct listNode *nextPtr;
};
typedef struct listNode ListNode;
typedef ListNode *ListNodePtr;
int main(void)
{
ListNodePtr startPtr = NULL;
char *zztop;
scanf("%s", &zztop);
printf("\n%s\n", &zztop);
insert(&startPtr, zztop);
}
void insert(ListNodePtr *sPtr, char *value)
{
ListNodePtr newPtr;
ListNodePtr previousPtr;
ListNodePtr currentPtr;
newPtr = malloc(sizeof(ListNode));
printf("\n %s \n", &value);
}
The printf value at the end of the insert function is merely a checkpoint to see if the data that was given to function insert is correct. However, random garbage is printed. Why?
My apologies if the question is convoluted, hope this makes some sense! Thanks