Menu driven program for all string functions.
#include<stdio.h>
#include<string.h>
int main(){
int c,l,i,j;
char str[100];
char str1[100];
char str2[100];
printf("\n");
printf("*****************************************\n");
printf(" MENU DRIVEN PROGRAM \n");
printf("*****************************************\n");
do{
printf("\n\n\n");
printf("1. Show address of each character in string.\n");
printf("2. Concatinate two string without strcat.\n");
printf("3. Concatinate two string with strcat.\n");
printf("4. Compare two strings.\n");
printf("5. Calculate length of string.\n");
printf("6. Convert all lowercase character to uppercase.\n");
printf("7. Convert all uppercase character to lowercase.\n");
printf("8. Calculate no of vowels.\n");
printf("9. Reverse a string.\n");
printf("10. Exit");
printf("\nEnter your choice : ");
scanf("%d",&c);
if (c==1){
printf("Enter the string : ");
fflush(stdin);
gets(str1);
for (i=0; str1[i]!='\0'; i++){
printf("%d\n",&str1[i]);
}
}
else if(c==2){
printf("Enter 1st string : ");
fflush(stdin);
gets(str1);
printf("Enter 2nd sting : ");
fflush(stdin);
gets(str2);
i=0;
while(str1[i]!='\0'){
str[i]=str1[i];
i++;
}
j=0;
while(str2[j]!='\0'){
str[i]=str2[j];
j++;
i++;
}
str[i]='\0';
printf("After concatination string is : %s",str);
}
else if(c==3){
printf("Enter 1st string : ");
fflush(stdin);
gets(str1);
printf("Enter 2nd sting : ");
fflush(stdin);
gets(str2);
strcat(str1,str2);
printf("After concatination string is : %s",str1);
}
else if(c==4){
printf("Enter 1st string : ");
fflush(stdin);
gets(str1);
printf("Enter 2nd sting : ");
fflush(stdin);
gets(str2);
i=strcmp(str1,str2);
if (i==0)
printf("Both strings are similar.");
else
printf("Both strings are not similar.");
}
else if(c==5){
printf("Enter the string : ");
fflush(stdin);
gets(str1);
i=strlen(str1);
printf("The length of the string is %d.",i);
}
else if (c==6){
printf("Enter the string : ");
fflush(stdin);
gets(str1);
strupr(str1);
printf("After changing the string the string is %s. ",str1);
}
else if (c==7){
printf("Enter the string : ");
fflush(stdin);
gets(str1);
strlwr(str1);
printf("After changing the string the string is %s. ",str1);
}
else if (c==8){
printf("Enter the string : ");
fflush(stdin);
gets(str1);
int count=0;
for (i=0; str1[i]!='\0'; i++){
if (str1[i]=='a' || str1[i]=='e' || str1[i]=='i' || str1[i]=='o' || str1[i]=='u' )
count++;
}
printf("The no of vowels in the string is = %d",count);
}
else if (c==9){
printf("Enter the string : ");
fflush(stdin);
gets(str1);
strrev(str1);
printf("After reversinng the string is %s.",str1);
}
else if(c==10){
printf("Bye Bye....mofo :-)");
break;
}
else
printf("Invalid choice..");
} while(1);
return 0;
}