Code:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<conio.h>
void main()
{int ch;
printf("1.Calculate the length of string\n2.Compare 2 strings\n3.Concatenate 2 strings\n4.Copy a string to another\n5.Change the string case\n6.Sentence case\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{ char s[20];
printf("Enter the string the length of which is to be calculated:\n");
gets(s);
int len=strlen(s);
printf("The length of the string %s is: %d",s,len);
}
break;
case 2:
{ char x[20],y[20];
printf("Enter the 2 strings to be compared:\n");
gets(x);
printf("\n");
gets(y);
printf("\n");
if(strcmp(x,y)==0)
printf("The 2 strings %s and %s are the same\n",x,y);
else
printf("The 2 strings %s and %s are not the same",x,y);
}break;
case 3:
{
char x[30],y[10];
printf("Enter the 2 strings to be concatenated:\n");
printf("x=");gets(x);printf("\ny=");
gets(y);
strcat(x,y);
printf("\n After concatenation the two strings are x=%s and %s",x,y);
}break;
case 4:
{
char s[20],copy[20];
printf("Enter the string to be copied into another string:\n");
gets(s);
strcpy(copy,s);
printf("The copied string is:%s",copy);
}break;
case 5 :
{
int c; char s[20];
printf("Enter the string");
gets(s);
int len=strlen(s);
printf("\nTo what case would you like the string to be converted?\n1.Upper\n2.Lower\n");
scanf("%d",&c);
switch(c)
{
case 1:
{
for(int i=0;i<len;i++)
s[i]=toupper(s[i]);
printf("The converted string is:\n");
puts(s);
}
break;
case 2:
{
for(int i=0;i<len;i++)
s[i]=tolower(s[i]);
printf("The converted string is:\n");
puts(s);
}
}
}break;
case 6:
{ char s[30];
printf("\nEnter the sentence");
gets(s);
int len=strlen(s);
s[0]=toupper(s[0]);
for(int i=0;i<len;i++)
{
if(s[i]==' ')
{
s[i+1]=toupper(s[i+1]);
}
}
printf("The converted string is:\n");
puts(s);
}
}
getch();
}
here gets() is nt working!! :'-(