i want to know whats the error over here. i just want to store the three value in a node and making a linked list but after storing two nodes that is headptr and than temptr, when the third node is made it stops.
I think my error is somewhere in "while loop" bt i couldnt find it.

node* addnode(int x, int r,int c)// x = value,r = row, c = coloumn
	
	{
	
		node* nodeptr = new node;
		node* temptr;
		temptr = headptr;
		nodeptr->val = x;;
		nodeptr->rowval = r;
		nodeptr->colval = c;
	    nodeptr->next = NULL;
		
		cout<<"nodeprtr->value"<<nodeptr->val<<endl;
		cout<<"nodeptr->row"<<nodeptr->rowval<<endl;
		cout<<"nodeptr->col"<<nodeptr->colval<<endl;
		if ( headptr == NULL )
		{
			headptr = nodeptr;
			cout<<"headptr->value"<<" "<<headptr->val<<endl;
			cout<<"headptr->row"<<" "<<headptr->rowval<<endl;
		    cout<<"headptr->col"<<" "<<headptr->colval<<endl;
			return headptr;
			
		}
		else
		{   
			 if (headptr != NULL )
			{
				 while(temptr->next!= NULL )
				{
					temptr->next = temptr;
				}
				 
			 }
			temptr->next = nodeptr;
			temptr = nodeptr;
			cout<<"temptr->val"<<" "<<temptr->val<<endl;
		cout<<"temptr->rowval"<<" "<<temptr->rowval<<endl;
		cout<<"temptr->colval"<<" "<<temptr->colval<<endl;
		return nodeptr;
		}
	}

Your statement

temptr->next = temptr;

should probably be

temptr = temptr->next;

There may be other problems, but this is a good place to start.

That said, I would like to suggest that you learn how to use code tags properly.

thanks it was the mistake. the code is running correctly

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.