Strcmp/strncmp

From 탱이의 잡동사니
Revision as of 13:01, 9 August 2016 by Pchero (talk | contribs) (Created page with "== Overview == strcmp/strncmp 내용 정리 == Synopsis == <source lang=c> #include <string.h> int strcmp(const char *s1, const char *s2); int strncmp(const char *s1, const...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Overview

strcmp/strncmp 내용 정리

Synopsis

<source lang=c>

  1. include <string.h>

int strcmp(const char *s1, const char *s2);

int strncmp(const char *s1, const char *s2, size_t n); </source>

Example

<source lang=c>

  1. include <stdio.h>
  2. include <string.h>

int main(int argc, char** argv) {

   char* tmp;
   int ret;
   
   tmp = "hello";
   ret = strncmp(tmp, "helloooo", strlen(tmp));
   
   printf("Reuslt. ret[%d]\n", ret);
   
   return 0;

} </source>

Results

$ valgrind --tool=memcheck --leak-check=full ./main
==32434== Memcheck, a memory error detector
==32434== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==32434== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==32434== Command: ./main
==32434== 
Reuslt. ret[0]
==32434== 
==32434== HEAP SUMMARY:
==32434==     in use at exit: 0 bytes in 0 blocks
==32434==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==32434== 
==32434== All heap blocks were freed -- no leaks are possible
==32434== 
==32434== For counts of detected and suppressed errors, rerun with: -v
==32434== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)