-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.c
39 lines (31 loc) · 875 Bytes
/
7.c
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
#include <stdio.h>
#include <string.h>
int main() {
const char *str1 = "Hello";
const char *str2 = "Hi";
int len1 = 0, len2 = 0;
while (str1[len1] != '\0') {
len1++;
}
while (str2[len2] != '\0') {
len2++;
}
if (len1 == len2) {
printf("Strings are equal in length.\n");
} else if (len1 > len2) {
printf("'%s' is longer than '%s'.\n", str1, str2);
} else {
printf("'%s' is longer than '%s'.\n", str2, str1);
}
printf("using library function.\n");
int str1Len = strlen(str1);
int str2Len = strlen(str2);
if (str1Len == str2Len) {
printf("Strings are equal in length.\n");
} else if (str1Len > str2Len) {
printf("'%s' is longer than '%s'.\n", str1, str2);
} else {
printf("'%s' is longer than '%s'.\n", str2, str1);
}
return 0;
}