Thursday

Write a C program to input a message from keyboard and display the menu.

a.       Print the message length in terms of characters.
b.      print the message in reverse order
c.       print the message in capital letters
d.      copy the message from one location of screen to another location. 

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char msg[100],msg1[100];
int i,ch,len,j;
clrscr();
printf("\n Enter a message:");
gets(msg);
printf("\n 1. Print the message length in terms of characters");
printf("\n 2. Print the message in reverse order");
printf("\n 3. Print the message in capital letters");
printf("\n 4. Copy the message from one location to another");
printf("\n Enter your choice (1-4)");
scanf("%d",&ch);
switch(ch)
{
 case 1:

 len=0;
 while(msg[len]!='\0')

 len++;
 printf("\n The string %s has %d characters\n",msg,len);
 break;
 case 2:
 len=strlen(msg);
 j=0;
 for(i=len-1;i>=0;i--)
 msg1[j++]=msg[i];
 msg[j]='\0';
 strcpy(msg,msg1);
 printf("\n The reversed string is %s",msg);
 break;
 case 3:
 for(i=0;msg[i]!='\0';i++)
 {
 if(msg[i]>='a' && msg[i]<='z')
 msg[i]=msg[i]-32;
 }
 printf("\n The message in uppercase %s",msg);
 break;
 case 4:
 for(i=0;msg[i]!='\0';i++)
 msg1[i]=msg[i];
 msg1[i]='\0';
 printf("The copied string is %s ",msg1);
 break;
 default:
 printf("\n Invalid choice");
 }
 getch();
 }

No comments:

Post a Comment

Rahul-Notes