Strcmp/strncmp: Difference between revisions
Jump to navigation
Jump to search
(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...") |
|||
Line 2: | Line 2: | ||
strcmp/strncmp 내용 정리 | strcmp/strncmp 내용 정리 | ||
== | == Basic == | ||
<source lang=c> | <source lang=c> | ||
#include <string.h> | #include <string.h> | ||
Line 10: | Line 10: | ||
int strncmp(const char *s1, const char *s2, size_t n); | int strncmp(const char *s1, const char *s2, size_t n); | ||
</source> | </source> | ||
strcmp()/strncmp() 사용시, 문자열 인자값에 NULL 이 입력되면 세그멘테이션 폴트를 일으킨다. | |||
== Example == | == Example == |
Latest revision as of 13:11, 9 August 2016
Overview
strcmp/strncmp 내용 정리
Basic
<source lang=c>
- include <string.h>
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n); </source>
strcmp()/strncmp() 사용시, 문자열 인자값에 NULL 이 입력되면 세그멘테이션 폴트를 일으킨다.
Example
<source lang=c>
- include <stdio.h>
- 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)