c - Adding Characters into Struct -
i trying read characters linked list (i made simple test code try read in characters) reason cannot read in character value.
#include <stdio.h> #include <stdlib.h> #include <string.h> struct node { char name[50]; struct node *next; }*head; void add(char addname); int main() { head = null; char tempname[50]; printf("what name"); scanf(" %s", tempname); add(tempname); printf("%s",head->name); return 0; } void add(char addname) { struct node *temp; temp = (struct node*)malloc(sizeof(struct node)); strcpy(temp->name,addname); head = temp; head->next = null; }
i understand not how linked list works made try able run single character name struct , print out. (i should able enter in name bob , prints bob)
i think function parameter definition wrong. try this:
void add(char *addname) { .... }
Comments
Post a Comment