Guest User

Untitled

a guest
Apr 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct listNode{
  5. char *data;
  6. struct listNode *next;
  7. } *ListNodePtr;
  8.  
  9.  
  10. typedef struct list {
  11. ListNodePtr head;
  12. } List;
  13.  
  14.  
  15.  
  16. List new_list(){
  17. List temp;
  18. temp.head = NULL;
  19. return temp;
  20. }
  21.  
  22.  
  23.  
  24. //Student Courses
  25.  
  26. void insert_at_front(ListNodePtr* head, char *data){
  27. ListNodePtr new_node = malloc(sizeof(struct listNode));
  28. new_node->data = data;
  29. new_node->next = *head;
  30. *head = new_node;
  31. }
  32.  
  33. void print_list(List *self)
  34. {
  35. ListNodePtr current = self->head;
  36. while(current!=NULL)
  37. {
  38. printf("%s n", current->data);
  39. current = current->next;
  40. }
  41.  
  42. printf("n");
  43. }
  44.  
  45.  
  46. int main()
  47. {
  48. char i = 'y';
  49. char *name;
  50. List mylist = new_list();
  51. while(i=='y'){
  52. printf("your name is :");
  53. scanf("%s",name);
  54. insert_at_front(&mylist.head,name);
  55. print_list(&mylist);
  56. }
  57.  
  58. return 0;
  59. }
Add Comment
Please, Sign In to add comment