Sunday, November 17, 2019

String operations using switch case in C


  • Program :
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int l, n;
char a[20], b[20], c[20];
clrscr();
printf("\n STRING OPERATIONS\t  \n1.String Concatenation\t  \n2.String Compare\t   \n3.String Copy\t  \n4.String Length\t  \n5.String Uppercase\t  \n6.String Lowercase\t  \n7.String Reverse\t  \n8.String Duplicate\t");
printf("\n Enter your choice:");
scanf("%d", &n);
switch(n)
{
case 1:
printf("\n Enter A :");
gets(a);
printf("\n Enter B :");
gets(b);
strcat(a, b);
printf("\n String concatenation :%s\t", a);
break;
case 2:
printf("\n Enter A :");
gets(a);
printf("\n Enter B :");
gets(b);
if(strcmp(a, b)==0)
printf("\n Strings are equal");
else
printf("\n Strings are not equal");
break;
case 3:
printf("\n Enter B :");
gets(b);
strcpy(c, b);
printf("\n String copy :%s\t", c);
break;
case 4:
printf("\n Enter A :");
gets(a);
l=strlen(a);
printf("\n length of string :%d\t", l);
break;
case 5:
printf("\n Enter A :");
gets(a);
printf("\n String uppercase:%s\n",strupr(a));
break;
case 6:
printf("\n Enter A :");
gets(a);
printf("\n String lowercase :%s\n",strlwr(a));
break;
case 7:
printf("\n Enter A :");
gets(a);
printf("\n String reverse :%s\n",strrev(a));
break;
case 8:
printf("\n Enter A :");
gets(a);
printf("\n String duplicate :%s\n",strdup(a));
break;
default:
printf("\n wrong entry");
}
getch();
}

1 comment:

Function Overloading in C++

https://monitechvenkat1620.blogspot.com Program : #include <iostream> using namespace std; int c(int x, int y) {   return...