problem in loc ptr

Write your question here.

#include<iostream>
#include<conio.h>
using namespace std;
struct node
{
int data;
node *next;
};
typedef node *list;
list head;
int search(list, int);
int main()
{
int dat, item;
char ch;
cout<<"Do you wish to enter data??"<<endl;
cin>>ch;
list temp;
int loc;
head=NULL;
while(ch=='y'||ch=='Y')
{
cout<<"Enter data"<<endl;
cin>>dat;
temp=new node;
temp->data=dat;
temp->next=head;
head=temp;
cout<<"Enter more data"<<endl;
cin>>ch;
}
cout<<"Item you wanna search"<<endl;
cin>>item;
loc=search(head, item);
cout<<"Item found at "<<loc<<endl;
return 0;
}

int search(list ptr, int item)
{
int loc=NULL;
while(ptr!=NULL)
{
if(item>ptr->data)
{
ptr=ptr->next;
}
else if(item==ptr->data)
{
loc=ptr;
//return loc;
}
else
{
ptr=NULL;
}
}
return loc;
}
What is the problem? What error message do you get?
Line 50: You're trying to assign a pointer (ptr) to an int (loc). Those are different types and that is not a valid assignment.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.