#include <stdio.h>
#include <stdlib.h>
struct LLNode
{
char key[10];
struct LLNode *next;
};
struct LLNode *creatNode(char val[10])
{
struct LLNode*temp;
temp=(struct LLNode *)malloc(sizeof(struct LLNode));
temp->key[10]=val;
temp->next=NULL;
return (temp);
};
void push(char val[10], struct LLNode *head)
{
struct LLNode *temp;
temp = creatNode(val[10]);
temp->next = head->next;
head->next = temp;
}
int main()
{
int cho,a=0;
struct LLNode *head=NULL;
struct LLNode *curr=NULL;
head=creatNode('/0');
curr=head;
curr->next = creatNode("Jan");
curr = curr->next;
curr->next = creatNode("Feb");
curr = curr->next;
curr->next = creatNode("Mar");
curr = curr->next;
curr->next = creatNode("Apr");
curr = curr->next;
curr->next = creatNode("May");
curr = curr->next;
curr->next = creatNode("Jun");
curr = curr->next;
curr->next = creatNode("Jul");
curr = curr->next;
curr->next = creatNode("Aug");
curr = curr->next;
curr->next = creatNode("Sep");
curr = curr->next;
curr->next = creatNode("Oct");
curr = curr->next;
curr->next = creatNode("Nov");
curr = curr->next;
curr->next = creatNode("Dec");
curr=head;
printf("1. Create a new node in the linked list\n");
printf("2. Search the month of 'May' in the linked list\n");
printf("3. Display the content of each node\n");
printf("4. Exit\n");
printf("\n\nPlease enter the serial number of your choice:");
scanf("%d",&cho);
switch(cho)
{
case 1:
push ("newnode", head);
printf("head->next->key = %s\n",head->next->key) ;
printf("the new node is insert successfully");
break;
case 2:
curr=head;
while(a==0)
{
if(curr->key[10]="May")a=1;
else curr=curr->next;
}
curr=head;
if(a==1) printf("\n'May'is in the list.\n");
else printf("\n'May'is not in the list.\n");
break;
case 3:
curr=head;
while(curr)
{
printf("%s ",curr->key);
curr=curr->next;
}
break;
case 4:
printf("You are exiting");
break;
}
return 0;
}
I'm learning about linked lists, but now every time I use this code, I get garbled in the string output in case1 and case3.
The purpose of this code is to implement the tasks in the image(In the link)
enter image description here The first time I used it, I found that I was asked to add a few more statements, so I copied some nonsense here The first time I used it, I found that I was asked to add a few more statements, so I copied some nonsense here The first time I used it, I found that I was asked to add a few more statements, so I copied some nonsense here The first time I used it, I found that I was asked to add a few more statements, so I copied some nonsense here