Program to perform the menu driven operations on strings using standard library functions


C File =>



/* Write a menu driven program to perform the following operations on using standard library functions:
1. Convert string to uppercase
2. Copy one string to another
3. Compare two strings
4. Concatenate two strings */


<stdio.h>
<string.h>
<stdlib.h>
<ctype.h>
int main()
{
     char s1[50],s2[50];
     int ch,i;
     printf("\nMenu :\n 1.Convert string to uppercase\n");
     printf(" 2. Copy one string to another\n");
     printf("3. Compare two strings\n 4. Concatenate two strings\n");
     printf("5. Exit\n Enter your choice : ");
     scanf("%d",&ch);
     switch(ch)
    {
        case 1: printf("\n Enter String: ");
                    scanf("%s",s1);
                    printf("\n Converted String: ");
                    for(i=0;i<strlen(s1);i++)
                        printf("%c",toupper(s1[i]));
       break;
        case 2: printf("\n Enter String: ");
                    scanf("%s",s1);
                    strcpy(s2,s1);
                    printf("\n Copied String is : %s",s2);
        break;
       case 3: printf("\n Enter string1 : ");
                   scanf("%s",s1);
                   printf("\n Enter String2 : ");
                   scanf("%s",s2);
                   if(strcmp(s1,s2)==0)
                       printf("\n Entered strings are equal...");
                   else
                      printf("\n Entered strings are different..");
        break;
        case 4: printf("\n Enter string1 : ");
                    scanf("%s",s1);
                    printf("\n Enter string2 : ");
                    scanf("%s",s2);
                    printf("\n Concatenated string : %s",strcat(s1,s2));
        break;
        case 5: exit(0);
        break;
        default: printf("\n Enter proper choice");
     } //end switch
return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.