Go Down

Topic: strncmp question (Read 4928 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?



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