Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <unistd.h>
- typedef struct node {
- int data;
- struct node *next;
- } node_t;
- void insert(node_t *head, int data)
- {
- node_t *new, *p;
- new = malloc(sizeof(node_t));
- if(new == NULL) {
- perror("memory can't be allocated");
- EXIT(EXIT_FAILURE);
- new->data = data;
- new->next = NULL;
- for(p = head; p->next != NULL; p = p->next)
- ;
- p->next = new;
- }
- void print_list(node_t *head)
- {
- node_t *p = head;
- while(p->next != NULL) {
- p = p->next;
- fprintf(stdout, "(PID: %d) Memory: %p | Data = %d | Next: %p\n", getpid(), p, p->data, p->next);
- }
- }
- int main(void)
- {
- node_t *head;
- pid_t pid;
- head = malloc(sizeof(node_t));
- if(new == NULL) {
- perror("memory can't be allocated");
- EXIT(EXIT_FAILURE);
- }
- head->next = NULL;
- head->data = 0;
- insert(head, 1);
- insert(head, 2);
- print_list(head);
- free(head);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement