-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrcmp.c
More file actions
31 lines (31 loc) · 836 Bytes
/
Copy pathstrcmp.c
File metadata and controls
31 lines (31 loc) · 836 Bytes
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
#include <stdio.h>
#include <string.h>
void findLength(char str[]) {
int length = 0;
while (str[length] != '\0') {
length++;
}
if (str[length - 1] == '\n') {
length--;
}
printf("Length of the string '%s' is: %d\n", str, length);
}
void compareStrings(char str1[], char str2[]) {
int result = strcmp(str1, str2);
if (result == 0) {
printf("The strings '%s' and '%s' are equal.\n", str1, str2);
} else {
printf("The strings '%s' and '%s' are not equal.\n", str1, str2);
}
}
int main() {
char str1[100], str2[100];
printf("Enter the first string: ");
fgets(str1, sizeof(str1), stdin);
printf("Enter the second string: ");
fgets(str2, sizeof(str2), stdin);
findLength(str1);
findLength(str2);
compareStrings(str1, str2);
return 0;
}