-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP319_Q8.cpp
66 lines (57 loc) · 997 Bytes
/
P319_Q8.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#pragma warning(disable:4996)
int str_cmp(const char* s1, const char* s2)
{
while (*s1 == *s2)
{
if (*s1 == '\0')
return 0;
s1++;
s2++;
}
return (unsigned char)*s1 - (unsigned char)*s2;
}
char Upper(char c)
{
if ('a' <= c && c <= 'z')
return c - 32;
}
int str_cmpic(const char* s1, const char* s2)
{
while (*s1 == Upper(*s2))
{
if (*s1 == '\0')
return 0;
s1++;
s2++;
}
return (unsigned char)*s1 - (unsigned char)Upper(*s2);
}
int str_ncmpic(const char* s1, const char* s2, size_t n)
{
int times = 0;
while (*s1 == Upper(*s2))
{
if (*s1 == '\0' || times >= n)
return 0;
s1++;
s2++;
++times;
}
return (unsigned char)*s1 - (unsigned char)Upper(*s2);
}
int main()
{
char st[128];
puts("\"ABCD\"와 비교합니다.");
puts("\"XXXX\"면 종료합니다.");
while (1)
{
printf("문자열 st: ");
scanf("%s", st);
if (str_cmpic("XXXX", st) == 0)
break;
printf("str_cmp(\"ABCD\", st) = %d \n", str_cmp("ABCD", st));
}
return 0;
}