Write a menu driven program in 'C' for the following: - calculating length of a given string and display the length. - copy one string into another string and display both the strings. - compare two strings and display the result. - concatenate two strings and display the resultant string. (By using standard functions)


#include
void main()
{
    char str1[80],str2[80];
    int  ch,temp;
    clrscr();
    do
    {
        printf("\nPRESS 1. TO CLACULATE LENGTH OF STRING.");
        printf("\nPRESS 2. TO COPY ONE STRING INTO ANOTHER STRING.");
        printf("\nPRESS 3. TO COMPARE TWO STRING. ");
        printf("\nPRESS 4. TO CONCATENATE TWO STRING.");
        printf("\nPRESS 5. TO EXIT.");
        printf("\nENTER YOUR CHOICE ::>");
        scanf("%d",&ch);
        switch(ch)
        {
        case 1:
            printf("\nENTER ANY STRING ::>\n");
            scanf("%s",str1);
            printf("\nLENGTH OF STRING ::> %d",strlen(str1));
            break;
        case 2:
            printf("\nENTER ANY STRING ::>\n");
            scanf("%s",str1);
            printf("The Copied string ::>\n%s", strcpy(str2,str1));
            break;
        case 3:
            printf("\nENTER ANY STRING ::>\n");
            scanf("%s",str1);
            printf("\nENTER ANY STRING ::>\n");
            scanf("%s",str2);
            temp = strcmp(str1,str2);
            if(temp == 0)
            {
                printf("\nBOTH STRINGS IS EQUAL.");
            }
            else
            {
                printf("\nBOTH STRINGS IS NOT EQUAL.");
            }
            break;
        case 4:
            printf("\nENTER ANY STRING ::>\n");
            scanf("%s",str1);
            printf("\nENTER ANY STRING ::>\n");
            scanf("%s",str2);
            strcat(str1,str2);
            printf("STRING AFTER CONCATENATION ::>\n%s",str1);
            break;
        case 5:
            exit(0);
        }
    }while(ch != 5);
    getch();
}
Write a menu driven program in 'C' for the following: - calculating length of a given string and display the length. - copy one string into another string and display both the strings. - compare two strings and display the result. - concatenate two strings and display the resultant string. (By using standard functions) Write a menu driven program in 'C' for the following: - calculating length of a given string and display the  length. - copy one string into another string and display both the  strings.  - compare two strings and display the result. - concatenate two strings and display the resultant  string. (By using standard functions) Reviewed by on April 24, 2015 Rating: 5
Powered by Blogger.