Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

char *, char[ ], and changing conditions.

Status
Not open for further replies.

PowerNuke

Programmer
Oct 7, 2001
10
US
Hi all,

My prog is crashing on the following statement:

while ( strcmp( abbrev[loop].initials, product ) != 0 && loop < size )


I get a &quot;illegal&quot; error from windows and the program dies.

char * initials
char product[75]
loop goes from 0 to size (around 150 lines)

I'm thinking that the problem is the char * -vs- char[ ], although there is no syntax error.

For all I know, you can't loop through the struct array in the while statement.

Any ideas or suggestions. I can provide more code if needed.

Thanks in advance.
 
One reason could be (from the code you've given us) that when an && statement is evaluated if the first term is false the second term is not evaluated (since there's no point, the statement will still evaluate to false). So your 'loop < size' statement is probably not being called in time to stop one more strcmp than is necessary being called causing your program to crash.

Try swapping them round in the while test. ie:
while (loop < size && strcmp( abbrev[loop].initials, product) != 0)

Hope this helps,

paulf.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top