forked from terodea/PG-DBDA
-
Notifications
You must be signed in to change notification settings - Fork 2
/
07-StringOperation.c
49 lines (46 loc) · 1.16 KB
/
07-StringOperation.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
40
41
42
43
44
45
46
47
48
49
#include<stdio.h>
#include<string.h>
int main(){
int a,b;
char s1[100],s2[100];
printf("Enter a string.\n");
scanf("%s",s1);
//strlen(),strrev(),strcat(),strcpy(),strupr(),strlwr(),strcmp()
printf("Enter the operation you wish to perform on the string:\n1. String Length\n2. String Concatenation\n3. String Copy\n4. String Comparison\n");
scanf("%d",&a);
switch(a)
{
case 1:
{
b=strlen(s1);
printf("String Length = %d",b);
break;
}
case 2:
{
printf("Enter the target string.\n");
scanf("%s",s2);
strcat(s2,s1);
printf("Result - %s",s2);
break;
}
case 3:
{
strcpy(s2,s1);
printf("Copied String - %s",s2);
break;
}
case 4:
{
printf("Enter the string you wish to compare with the previous string.\n");
scanf("%s",s2);
a=strcmp(s1,s2);
printf("String Compare %d",a);
break;
}
default:
{
printf("You have not entered a valid option.");
}
}
}