Go Down

Topic: strncmp question (Read 1 time) previous topic - next topic

alfiesty

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?

Jim
8000ft above the average

guix

#1
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 :)

http://www.cplusplus.com/reference/clibrary/cstring/strncmp/

PaulS

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

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!

Arduino
via Egeo 16
Torino, 10131
Italy