//PROGRAM TO ERFORM STRING FUNCTION - STRING LENGTH, COPY, CONCATENATE, REVERSE, COMBINE, EXTRACT & COMPARE
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void string_length()
{
int i=0;
char str[100];
gets(str);
printf("\n\nEnter The String : ");
gets(str);
while(str[i]!='\0')
i++;
printf("\n\nLENGTH Of The String is : %d Characters",i);
}
void string_concatenate()
{
int i=0,p=0;
char str1[100],str2[100];
gets(str1);
printf("\n\nEnter The String : ");
gets(str1);
printf("\nEnter The String B : ");
gets(str2);
while(str1[p]!='\0')
p++;
for(i=0;str2[i]!='\0';i++,p++)
str1[p]=str2[i];
printf("\n\nThe CONCATENATED String is : ");
for(i=0;i<p;i++)
printf("%c",str1[i]);
}
void string_reverse()
{
int i=0,p=0,q=0;
char str1[100],str2[100];
gets(str1);
printf("\n\nEnter The String : ");
gets(str1);
while(str1[p]!='\0')
p++;
for(i=p-1;i>=0;i--,q++)
str2[i]=str1[q];
printf("\n\nREVERSED String : ");
for(i=0;i<q;i++)
printf("%c",str2[i]);
}
void string_copy()
{
int i=0,p=0;
char str1[100],str2[100];
gets(str1);
printf("\n\nEnter The String : ");
gets(str1);
while(str1[p]!='\0')
p++;
for(i=0;i<p;i++)
str2[i]=str1[i];
printf("\n\nCOPIED String : ");
for(i=0;i<p;i++)
printf("%c",str2[i]);
}
void string_combine()
{
int i=0,p=0,j;
char str1[100],str2[100],str3[100];
gets(str1);
printf("\n\nEnter The String : ");
gets(str1);
printf("\nEnter The String B : ");
gets(str2);
while(str1[p]!='\0')
p++;
for(i=0;i<p;i++)
str3[i]=str1[i];
for(j=0;str2[j]!='\0';j++,i++)
str3[i]=str2[j];
printf("\n\nThe COMBINED String is : ");
for(j=0;j<i;j++)
printf("%c",str3[j]);
}
void string_compare()
{
int p=0,q=0,d=0,e=0,k=0,i,t;
char str1[100],str2[100];
gets(str1);
printf("\nEnter The String A : ");
gets(str1);
printf("\nEnter The String B : ");
gets(str2);
while(str1[p]!='\0')
p++;
while(str2[q]!='\0')
q++;
if(p>q)
t=p;
else
t=q;
for(i=0;i<t;i++,d=0,e=0)
{
d=str1[i];
e=str2[i];
if(d!=e)
{
k++;
printf("\n\nRESULT = %d | The Strings Are NOT EQUAL",d-e);
break;
}}
if(k==0)
printf("\n\nTHE STRINGS ARE EQUAL");
}
void string_extract()
{
int o,q,j,p=0,i,t;
char str[100],str1[100];
gets(str);
printf("\n\nEnter The String : ");
gets(str);
printf("\n\nEnter The Position From Which Extraction Is To Be Done : ");
scanf("%d",&o);
printf("\n\nEnter The Length Of The String To Be Extracted : ");
scanf("%d",&q);
while(str[p]!='\0')
p++;
if(p-o<q)
t=p-0;
else
t=q;
for(i=0;i<p;i++)
if(i==(o-1))
for(j=0;j<q;j++,i++)
str1[j]=str[i];
printf("\n\nThe EXTRACTED String is : ");
for(j=0;j<t;j++)
printf("%c",str1[j]);
}
void main()
{
int op;
char v;
do{
clrscr();
printf("\nOPTIONS :\n\t1.Length Of String\n\t2.Concatinating String\n\t3.Reversing String\n\t4.Copy String\n\t5.Combine Strings\n\t6.Comparing Strings\n\t7.Extracting String\n\n\nEnter Choice :");
scanf("%d",&op);
switch(op)
{
case 1:
string_length();
break;
case 2:
string_concatenate();
break;
case 3:
string_reverse();
break;
case 4:
string_copy();
break;
case 5:
string_combine();
break;
case 6:
string_compare();
break;
case 7:
string_extract();
break;
default:
printf("\n\nINVALID CHOICE !!!");
break;
}
printf("\n\n\n\nPress 'e' To EXIT & Any Other Key To Continue : ");
scanf(" %c",&v);
}while(v!='e');
}
/*
OUTPUT
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :1
Enter The String : Checking The Length
LENGTH Of The String is : 19 Characters
Press 'e' To EXIT & Any Other Key To Continue : c
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :2
Enter The String : Checking
Enter The String B : Concatination
The CONCATENATED String is : CheckingConcatination
Press 'e' To EXIT & Any Other Key To Continue : c
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :3
Enter The String : Checking String Reverse
REVERSED String : esreveR gnirtS gnikcehC
Press 'e' To EXIT & Any Other Key To Continue : c
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :4
Enter The String : Copying A String
COPIED String : Copying A String
Press 'e' To EXIT & Any Other Key To Continue : c
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :5
Enter The String : Testing
Enter The String B : For Combining Strings
The COMBINED String is : TestingFor Combining Strings
Press 'e' To EXIT & Any Other Key To Continue : c
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :6
Enter The String A : String Comparing
Enter The String B : Is Tested
RESULT = 10 | The Strings Are NOT EQUAL
Press 'e' To EXIT & Any Other Key To Continue : c
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :7
Enter The String : Sting Is To Be Extracted
Enter The Position From Which Extraction Is To Be Done : 2
Enter The Length Of The String To Be Extracted : 6
The EXTRACTED String is : ting I
Press 'e' To EXIT & Any Other Key To Continue : e
*/
Programs Can Also Be Downloaded From The Folders Below....[Or Scroll Down]
String Functions - Length, Concatenate, Reverse, Copy, Combine, Compare & Extract
Click Here To Download C File Of This Program
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment