Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct node
- {
- char *name;
- float salary;
- struct node *nextNode;
- };
- struct list
- {
- struct node *firstNode;
- };
- void insert(struct list *pList, char *newName, float newSalary)
- {
- struct node *newNode;
- newNode = (struct node *)malloc(sizeof(struct node));
- newNode->salary = newSalary;
- newNode->name = newName;
- if (pList->firstNode == NULL)
- {
- pList->firstNode = newNode;
- newNode->nextNode = NULL;
- }
- else
- {
- struct node *pos = pList->firstNode;
- for(; pos->nextNode; pos = pos->nextNode);
- pos->nextNode = newNode;
- newNode->nextNode = NULL;
- }
- }
- int main(void)
- {
- struct list lst;
- struct list *plst = &lst;
- createList(plst); //initializes the list
- char name1[] = "John";
- char name2[] = "Thomas";
- char name3[] = "Albert";
- insert(plst, name1, 1000);
- insert(plst, name2, 2000);
- insert(plst, name3, 3000);
- }
- newNode->name = newName;
- strcpy(newNode->name,newName);
- newNode->name = malloc(strlen(newName)+1);
- strcpy(newNode->name,newName);
Add Comment
Please, Sign In to add comment