-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringfunctions.c
More file actions
81 lines (81 loc) · 1.67 KB
/
Copy pathstringfunctions.c
File metadata and controls
81 lines (81 loc) · 1.67 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
/*-------------------------------------------------------------------------------------------------------------------------------
StringFunctions.c
Program to perform string functions
DIVYA RAJ K
11-11-2018
---------------------------------------------------------------------------------------------------------------------------------*/
#include<stdio.h>
int fnStrlen(char S[20]);
void fncpstr(char S[20],char T[20]);
int fncmpstr(char S[20],char T[20]);
void fnstrjoin(char T[20],char S[20]);
main()
{
char S[20],T[20];
int len,cmp;
system("clear");
printf("1.To find the length of the string\nEnter a string: ");
scanf("%s",S);
len=fnStrlen(S);
printf("\nThe length of the string = %d",len);
printf("\n\n2.To copy one string to another string\nEnter a string: ");
scanf("%s",S);
fncpstr(S,T);
printf("\nSource = %s\nTarget = %s",S,T);
printf("\n\n3.To compare two strings\nEnter 2 strings: ");
scanf("%s",S);
scanf("%s",T);
cmp=fncmpstr(S,T);
if(cmp==0)
printf("\nTwo strings are equal!");
else if(cmp<0)
printf("\nString 1 is small");
else
printf("\nString 2 is small");
printf("\n\n4.To join two strings\nEnter 2 strings: ");
scanf("%s",T);
scanf("%s",S);
fnstrjoin(T,S);
printf("\nResultant string = %s",T);
}
int fnStrlen(char S[20])
{
int i=0;
while(S[i]!='\0'){
i++;
}
return i;
}
void fncpstr(char S[20],char T[20])
{
int i=0;
while(S[i]!='\0'){
T[i]=S[i];
i++;
}
T[i]='\0';
}
int fncmpstr(char S[20],char T[20])
{
int i=0;
while(S[i]==T[i]){
if(S[i]=='\0'){
return 0;
}
i++;
}
return S[i]-T[i];
}
void fnstrjoin(char T[20],char S[20])
{
int i=0,j=0;
while(T[i]!='\0'){
i++;
}
while(S[j]!='\0'){
T[i]=S[j];
i++;
j++;
}
T[i]='\0';
}