0% found this document useful (0 votes)
11 views

Program 8

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Program 8

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>
int main()
{
char string1[50];
char string2[50];
int a;
int i;
int j;
printf("Enter 1 to find length of the string:");
printf("\n");
printf("Enter 2 to find concatenate of two strings:");
printf("\n");
printf("Enter 3 to find reverse of a string:");
printf("\n");

printf("Enter your choice:");


scanf("%d",&a);

switch(a)
{
case 1:
int length=0;
printf("Enter the string:");
printf("\n");
scanf("%s",&string1);

for(i=0;string1[i]!='\0';i++)
{
length++;
}
printf("Length of the string is:");
printf("\n");
printf("\n");
printf("%d",length);
break;

case 2:
printf("Enter the first string:");
printf("\n");
scanf("%s",&string1);
printf("Enter the second string:");
printf("\n");
scanf("%s",&string2);

for(i=0;string1[i]!='\0';++i);
for(j=0;string2[j]!='\0';++j,++i)
{
string1[i]=string2[j];
}
string1[i]='\0';
printf("Concatenated string is:");
printf("\n");
printf("%s",string1);
break;

case 3:
printf("Enter a string to be reversed:");
printf("\n");
scanf("%s",&string1);
i=0;
while(string1[i]!='\0')
i++;
i--;

j=0;
while(i>=0)
{
string2[j]=string1[i];
j++;
i--;
}
string2[j]='\0';
printf("Reversed string is:");
printf("\n");
printf("%s",string2);
break;

default:
printf("Enter a valid choice.");
break;
}
return 0;
}

You might also like