0
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.

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by daviddoria
1

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

Votes + Comments
all good suggestons
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.