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.
C++ newsgroup welcome message:
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
http://www.josuttis.com -- C++ STL Library book
|All times are GMT. The time now is 03:01 AM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.