Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct listNode{
- char *data;
- struct listNode *next;
- } *ListNodePtr;
- typedef struct list {
- ListNodePtr head;
- } List;
- List new_list(){
- List temp;
- temp.head = NULL;
- return temp;
- }
- //Student Courses
- void insert_at_front(ListNodePtr* head, char *data){
- ListNodePtr new_node = malloc(sizeof(struct listNode));
- new_node->data = data;
- new_node->next = *head;
- *head = new_node;
- }
- void print_list(List *self)
- {
- ListNodePtr current = self->head;
- while(current!=NULL)
- {
- printf("%s n", current->data);
- current = current->next;
- }
- printf("n");
- }
- int main()
- {
- char i = 'y';
- char *name;
- List mylist = new_list();
- while(i=='y'){
- printf("your name is :");
- scanf("%s",name);
- insert_at_front(&mylist.head,name);
- print_list(&mylist);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment