[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppStrncmp

(C++) std::strncmp

A Standard function that compares two strings for a desired number of characters. To compare the whole string, use std::strcmp.

Use std::string instead of an array of char [1,2].

  1. include <cassert>
  2. include <cstring>
int main() { const char * const word1 = "ABC"; const char * const word2 = "ABCD"; // word1 precedes word2 according to std::stdcmp assert(std::strcmp( word1,word2) < 0); // word1 is equal to word2 // according to std::stdncmp // because only the first three characters // are compared assert(std::strncmp(word1,word2,3) == 0); }


Code links

Reference



last edited (March 29, 2007) by bilderbikkel, Number of views: 1290, Current Rev: 3 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.