Hey there,
i\m building a linked list and i need help with a display function i have.
the display function displays all the letters of the word entered instead of the word itself.
appreciate if someone could help me
below is my struct, one of my functions and the display function.
Code://-----------struct ------------//
struct Node
{
char data;
struct Node *next;
}*Head;
//-----------one of my functions--------//
void insert_beg(char info) // Inserting a node at the beginning of the list
{
struct Node *temp;
temp =(struct Node *)malloc(sizeof(struct Node)); // Allocating size
temp->data = info;
if (Head == NULL) // meaning list is empty
{
Head = temp;
Head->next = NULL;
}
else
{
temp->next = Head;
Head = temp;
}
}
//----MY DISPLAY FUNCTION-----//
void Display()
{
struct Node *cur_ptr;
cur_ptr = Head;
if (cur_ptr == NULL)
{
printf("\nList is empty");
}
else
{
printf("\nElements in the list:\n");
while (cur_ptr != NULL) // Traversing the entire linked list
{
printf("-> %c", cur_ptr->data);
cur_ptr=cur_ptr->next;
}
printf("\n");
}
}
//------------in my main-----------//
int main(int argc, const char * argv[])
{
int i=0;
Head = NULL;
printf("---------------MAIN MENU---------------\n");
printf("***************************************\n");
printf("Insert your data:\n");
printf("\t[1]-At The Beginning.\n");
printf("\t[2]-At The End.\n");
printf("\t[3]-At A Particular Location In The List\n");
printf("\t[4]-Print The Elements In The List\n");
printf("\t[5]-Print Number Of Elements In The List\n\n");
printf("-------------------------------------------\n");
printf("\t\tDelete A Node In The List\n");
printf("-------------------------------------------\n");
printf("\t[6]-Delete A Node Based By Element\n");
printf("\t[7]-Delete A Node Based On Location\n");
printf("\t[8]-EXIT\n");
printf("-------------------------------------------\n");
printf("Press 'x' to display MENU \n\n");
printf("\n\tChoose An Option:");
while (1)
{
scanf("%d", &i);
switch (i)
{
case 1:
{
char info;
printf("Enter your word:");
scanf(" %c", &info);
insert_beg(info);
Display();
break;
}