HI ,

i have some errors about linked list,when i made print it only shows
characeters like 'ô¼'... plz help; :lol: // lets assume wordCount is 10 and
vayArray is {"lower",upper}; :cool:

Thank you very much

Here is code:

struct for_char_5
{
	char vh5[80];	for_char_5 *next;
};

for_char_5 *p,
	   *start,
	   *end;


void create_linked_list ()
{
	p=new for_char_5;
	start=p;

	for (int i=0;i<wordCount;i++)
	{
		if (strlen(vayArray[i])==5)
			strcpy((*p).vh5,vayArray[i]);
		end=p;
		p=new for_char_5;

	}
	(*end).next=NULL;
}
Member Avatar for iamthwee

Huh, care to elaborate?

there are a lot of errors in that code. For example, in a linked list, the next item is supposed to point to the next node in the list.

start->next >>> node->next >>> node->next ...

The end of the linked list is noted when next == NULL.

Your program does not set the next member, so consequently it does not create a linked list.

void create_linked_list ()
{
	start = NULL;
        end = NULL;

	for (int i=0;i<wordCount;i++)
	{
		if (strlen(vayArray[i])==5)
                {
                      p = new for_char_5;
                      p->next = NULL;
		     strcpy(p->vh5,vayArray[i]);
                     if(start == NULL)
                     {
                            start = p;
                            end = p;
                      }
                     else
                     {
                            end->next = p;
                            end = p;
                      }
                }
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.