Go Down

Topic: strncmp question (Read 3762 times) previous topic - next topic


I have the line            if(strncmp(pch,"=1",1) == 0)                in my code. pch is "Chapter 1, page 23". As I understand the if should return a 0.  It doesn't,why?

8000ft above the average


Oct 18, 2012, 03:48 am Last Edit: Oct 18, 2012, 03:52 am by guix Reason: 1
Well no, it shouldn't return 0 because you are comparing only the first character, also there is no "=" sign in pch :)



also there is no "=" sign in pch

Specifically, the FIRST character is not '='.

The strncmp() function compares the first n characters. There are other functions, like strstr() that look for a string anywhere inside another string.
The art of getting good answers lies in asking good questions.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131