#include <stdio.h>
#include <string.h>
int str_ncmp(const char *s1, const char *s2, size_t n)
{
for(size_t i = 0; i<n;i++){
if(s1[i]!=s2[i])
return s1[i]-s2[i];
}
return 0;
}
int main(void)
{
char st[128];
puts("\"STRING\"의 처음 3개의 문자와 비교합니다.");
puts("\"XXXX\"를 입력하면 종료합니다.");
while (1)
{
printf("문자열 st : ");
scanf("%s", st);
if (str_ncmp("XXXX", st, 3) == 0)
break;
printf("str_ncmp(\"STRING\",st,3) = %d\n", str_ncmp("STRING", st, 3));
}
return 0;
}
'TEST > 자료구조와 함께 배우는 알고리즘 입문(C언어)' 카테고리의 다른 글
<8> Q9. 자료구조와 함께 배우는 알고리즘 입문 (C언어) (0) | 2021.07.22 |
---|---|
<8> Q8. 자료구조와 함께 배우는 알고리즘 입문 (C언어) (0) | 2021.07.22 |
<7> Q2. 자료구조와 함께 배우는 알고리즘 입문 (C언어) (0) | 2021.07.13 |
<7> Q1. 자료구조와 함께 배우는 알고리즘 입문 (C언어) (0) | 2021.07.07 |
<6> Q24. 자료구조와 함께 배우는 알고리즘 입문 (C언어) (0) | 2021.05.24 |