![]() |
Re: memcmp versus strstr; reaction to chr(0)
Walter Dnes wrote:
> When I asked in another thread about string comparisons, I forgot > about the chr(0) booby-trap in C strings. Since I want to compare > random binary data, this is important to me. Someone correct me if I'm > wrong; strstr stops at chr(0). memcmp doesn't treat chr(0) as a > delimiter, and can compare ranges (the word "strings" is incorrect here) > that included embedded chr(0). I realize that memcmp won't > automatically scan a larger string, but I can put it in a loop to sweep > through a larger string. Too bad that memmem is not standard. > The function memcmp() compares two regions of memory. The function strstr() searches a string for another (sub-)string. A string is a collection of chars terminated by a '\0'. If the string is not terminated correctly, undefined behavior occurs. -- Thomas Matthews C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt C++ Faq: http://www.parashift.com/c++-faq-lite C Faq: http://www.eskimo.com/~scs/c-faq/top.html alt.comp.lang.learn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html Other sites: http://www.josuttis.com -- C++ STL Library book |
| All times are GMT. The time now is 09:31 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.