Pages: [1]   Go Down
Author Topic: strncmp question  (Read 706 times)
0 Members and 1 Guest are viewing this topic.
Buena Vista, CO
Offline Offline
Full Member
***
Karma: 0
Posts: 181
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

8000ft above the average

France
Offline Offline
God Member
*****
Karma: 34
Posts: 987
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well no, it shouldn't return 0 because you are comparing only the first character, also there is no "=" sign in pch smiley

http://www.cplusplus.com/reference/clibrary/cstring/strncmp/
« Last Edit: October 17, 2012, 08:52:41 pm by guix » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: