-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuilt_in_function_string.c
More file actions
116 lines (106 loc) · 2.16 KB
/
Built_in_function_string.c
File metadata and controls
116 lines (106 loc) · 2.16 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include<stdio.h>
#include<string.h>
void length(char s[]){
int count = 0;
for(int i=0;s[i]!='\0';i++){
count++;
}
printf("Lenth of your string : %d\n",count);
}
void lower(char s[]){
printf("lower case string : ");
for(int i = 0;s[i]!='\0';i++){
if(s[i]>='a' && s[i]<='z'){
printf("%c",s[i]);
}
else if(s[i]==' '){
printf(" ");
}
else{
char ch = s[i] + 32;
printf("%c",ch);
}
}
}
void upper(char s[]){
printf("\nUpper case string : ");
for(int i = 0;s[i]!='\0';i++){
if(s[i]>='A' && s[i]<='Z'){
printf("%c",s[i]);
}
else if (s[i]==' '){
printf(" ");
}
else{
char ch = s[i] - 32 ;
printf("%c",ch);
}
}
}
void reverse(char s[]){
printf("\nReverse of the string : ");
int len = strlen(s) - 1;
for(int i = len;i>=0;i--){
printf("%c",s[i]);
}
}
void concatenate(char s[],char s2[]){
printf("\nconcatenate the two strings : ");
char s3[100];
int i = 0, j= 0;
while(s[i]!='\0'){
s3[j] = s[i];
i++;
j++;
}
i = 0;
while(s2[i] != '\0'){
s3[j] = s2[i];
j++;
i++;
}
s3[j] = '\0';
for(int i = 0;i<strlen(s3);i++){
printf("%c",s3[i]);
}
}
void checksame(char s[],char s2[]){
int check = 0;
for(int i = 0;s[i]!='\0';i++){
if(s[i]!=s2[i]){
printf("\nstrings are not same \n");
check++;
break;
}
}
if(check==0){
printf("\nstrings are same \n");
}
}
int palidrome(char s[]){
int l = 0, h = strlen(s)-1;
while(l<h){
if(s[l++] != s[h--]){
printf("\nnot palindrome\n");
return 0;
}
}
printf("palindrome\n");
return 0;
}
int main(){
char s[100];
printf("Enter a string : ");
gets(s);
reverse(s);
char s2[100];
printf("\nEnter second string : ");
gets(s2);
checksame(s,s2);
length(s);
lower(s);
upper(s);
concatenate(s,s2);
palidrome(s);
return 0;
}