struct node
{
    char str[10];
    int val;
    node *next;
};
void main()
{
clrscr();
node *head=NULL;int cnt=0;
cout<<"Continue... [Y/N]";char ch;cin>>ch;
    while(ch!='n')
    {
        node *temp;
        cout<<"Str= ";cin>>temp->str;
        cout<<"val= ";cin>>temp->val;
        temp->next=head;
        head=temp;
        cnt++;
        cout<<"Continue... [Y/N]";cin>>ch;
    }
    node *temp1;
    temp1=head;
    while(temp1!=NULL)
    {
        cout<<temp1->str<<"  ";
        cout<<temp1->val<<endl;
        temp1=temp1->next;

    }

 getch();
}

Plz help me out....... i have created a linklist each node having two values integer val and char str.. integer value is printing bt i cant print my str value thru this statment "cout<<temp1->str" rather it is printing a grabage value.

Welcome DaniWeb! A few suggestions:
1) Use code tags when posting code. It makes the code much easier for us to read.
2) Use real English words. I.e. "Please" instead of "Plz". It helps the community maintain a professional image.

3) You are outputting 'str' before assigning anything to it. Of course it will be garbage.
4) You should use std::string instead of char[].

Good luck,

David

commented: all good suggestons +35
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.