3 Replies - 216 Views - Last Post: 10 October 2012 - 01:40 PM Rate Topic: -----

#1 rainalyn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-October 12

Question: how to Search by integer in Linked List

Posted 10 October 2012 - 10:36 AM

everytime i run it, it crashes when i try to run this part.
how do i search by an integer.

int searchByRuns(PLAYER *play)
{
int runs;

system("cls");
printf("\n\t~~ Search by Number of Runs ~~");
printf("\n\n\t** Runs : ");
scanf("%d",runs);
while(play != NULL)
{
if((runs, play->runs) = runs) >.<
{
return showCurrentNode(play);
}
else
{
play = play->link;
}
}
printf("\n\n\tSorry, the specified Cricketer was not found");
getchar();
return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Question: how to Search by integer in Linked List

#2 sk1v3r  Icon User is offline

  • D.I.C Addict

Reputation: 231
  • View blog
  • Posts: 668
  • Joined: 06-December 10

Re: Question: how to Search by integer in Linked List

Posted 10 October 2012 - 11:01 AM

When passing a variable to scanf you must ensure that you are not sending the value of the variable, but rather the address.
For example
int a = 4;
int b = 4;
scanf("%d", a);
scanf("%d", B)/>;


both of these are essentially just doing the same as
scanf("%d", 4);


Which isn't tremendously useful (or safe).

You must pass the address of the variable, so that its value may be changed.

int a = 4;
scanf("%d", &a);



Also, there is a difference between the = operator and the [il]==[il/] operator. You would need to use the second in an if statement to compare two values.
However, your if statement looks odd to me anyway, what are you trying to do?

This post has been edited by sk1v3r: 10 October 2012 - 11:04 AM

Was This Post Helpful? 1
  • +
  • -

#3 NathanMullenax  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 83
  • View blog
  • Posts: 176
  • Joined: 23-September 12

Re: Question: how to Search by integer in Linked List

Posted 10 October 2012 - 11:01 AM

This line is just weird:

if((runs, play->runs) = runs){}



You probably want:

if( play->runs==runs )
{
}



Comma is the sequence operator--'runs,' effectively does nothing. If you want to check if runs is non-zero, you would do:

if( runs && play->runs==runs )



Or more clearly:

if( runs>0 && play->runs==runs )


Was This Post Helpful? 1
  • +
  • -

#4 rainalyn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-October 12

Re: Question: how to Search by integer in Linked List

Posted 10 October 2012 - 01:40 PM

yup! that did the trick! thank you both very much!! :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1