-
Notifications
You must be signed in to change notification settings - Fork 11
/
string.cpp
46 lines (46 loc) · 1.04 KB
/
string.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
#include <stdio.h>
#include <string.h>
int main()
{
printf("Enter the two strings\n");
char s[100],sc[100];
scanf("%[^\n]s", sc);
fflush(stdin);
scanf("%[^\n]s", s);
printf("Enter your choice\n1. With strcmp function\n2. Without strcmp function\n");
int c,i,k=0;
scanf("%d", &c);
switch(c)
{
case 2:
i=0;
while(s[i]!='\0' || sc[i]!='\0')
{
if(s[i]>sc[i])
{
printf("-1\n");
break;
}
else if(s[i]<sc[i])
{
printf("1\n");
break;
}
else if(s[i]==sc[i])
{
k++;
}
i++;
}
if(k==(strlen(s)))
printf("0\n");
break;
case 1:
printf("%d", strcmp(sc,s));
break;
default:
printf("Wrong Choice\n");
}
getch();
return 0;
}