Program to implement string library functions
/* Program to implement string library functions */
#include
#include
void main()
{
char s1[10],s2[10];
int i;
int choice;
printf("\n 1 for STRING COMPARE");
printf("\n 2 for STRING LENGTH ");
printf("\n 3 for STRING CONCATENATION ");
printf("\n Enter the choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter the string:");
scanf("%s",s1);
printf("\nEnter the string:");
scanf("%s",s2);
if(!strcmp(s1,s2))
printf("\nEqual");
else
printf("\nNot Equal");
break;
case 2:
printf("\nEnter the string:");
scanf("%s",s1);
i=strlen(s1);
printf("\nLength: %d",i);
break;
case 3:
printf("\nEnter the string:");
scanf("%s",s1);
printf("\nEnter the string:");
scanf("%s",s2);
strcat(s1,s2);
printf("\nString: %s",s1);
break;
default:
printf("\nWrong Option...");
}
}
#include
#include
void main()
{
char s1[10],s2[10];
int i;
int choice;
printf("\n 1 for STRING COMPARE");
printf("\n 2 for STRING LENGTH ");
printf("\n 3 for STRING CONCATENATION ");
printf("\n Enter the choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter the string:");
scanf("%s",s1);
printf("\nEnter the string:");
scanf("%s",s2);
if(!strcmp(s1,s2))
printf("\nEqual");
else
printf("\nNot Equal");
break;
case 2:
printf("\nEnter the string:");
scanf("%s",s1);
i=strlen(s1);
printf("\nLength: %d",i);
break;
case 3:
printf("\nEnter the string:");
scanf("%s",s1);
printf("\nEnter the string:");
scanf("%s",s2);
strcat(s1,s2);
printf("\nString: %s",s1);
break;
default:
printf("\nWrong Option...");
}
}
//string handling function using switch case
ReplyDelete#include
#include
#include
void main()
{
char s1[10],s2[10],s3[10];
int choice=0,n=0;
printf("\n1.lenth of string \n2.copy of string \n3.combination of string \n4.compare the string");
printf("\nEnter your choice=");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter the string=");
scanf("%s",s3);
printf("Length of string=%d",strlen(s3));
break;
case 2:
printf("enter 1st string=");
scanf("%s",s1);
printf("enter 2nd string=");
scanf("%s",s2);
strcpy(s1,s2);
printf(" after copy 1st string=%s 2nd string=%s ",s1,s2);
break;
case 3:
printf("enter 1st string=");
scanf("%s",s1);
printf("enter 2nd string=");
scanf("%s",s2);
strcat(s1,s2);
printf("contatiation of string=%s,%s",s1,s2);
break;
//string handling functions using switch case
ReplyDelete#include
#include
#include
char s1[10],s2[10],s3[10];
int choice=0,n=0;
void main()
{
printf("\n1.length of string \n2.copy the string \n3.contatiation of string \n4.comparision of string");
printf("\nenter ur choice");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nenter ur string");
scanf("%s",s3);
printf("\nstring length=%d",strlen(s3));
break;
case 2:
printf("\nenter ur 1st string");
scanf("%s",s1);
printf("\nenter ur 2nd string");
scanf("%s",s2);
strcpy(s1,s2);
printf("\nafter copy 1st string=%s 2nd string=%s",s1,s2);
break;
case 3:
printf("\nenter ur 1st string");
scanf("%s",s1);
printf("\nenter ur 2nd string");
scanf("%s",s2);
strcat(s1,s2);
printf("\nafter combine 2 strings=%s,%s",s1,s2);
break;
case 4:
printf("\nenter 1st string");
scanf("%s",s1);
printf("\nenter 2nd string");
scanf("%s",s2);
n=strcmp(s1,s2);
if(n==0)
{
printf("\nstrings r equal");
}
else if(n>0)
{
printf("\n1st is greater");
}
else
{
printf("\n1st string is small");
}
break;
default:
printf("\ninvalid choice");
}
}
//string handling function using switch case
ReplyDelete#include
#include
#include
void main()
{
char s1[10],s2[10],s3[10];
int choice=0,n=0;
printf("\n1.lenth of string \n2.copy of string \n3.combination of string \n4.compare the string");
printf("\nEnter your choice=");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter the string=");
scanf("%s",s3);
printf("Length of string=%d",strlen(s3));
break;
case 2:
printf("enter 1st string=");
scanf("%s",s1);
printf("enter 2nd string=");
scanf("%s",s2);
strcpy(s1,s2);
printf(" after copy 1st string=%s 2nd string=%s ",s1,s2);
break;
case 3:
printf("enter 1st string=");
scanf("%s",s1);
printf("enter 2nd string=");
scanf("%s",s2);
strcat(s1,s2);
printf("contatiation of string=%s,%s",s1,s2);
break;
case 4:
printf("enter 1st string=");
scanf("%s",s1);
printf("enter 2nd string=");
scanf("%s",s2);
n=strcmp(s1,s2);
if(n==0)
{
printf("two stings are equal=");
}
else if(n>0)
{
printf("1st string is greater=");
}
else
{
printf("1st string is small=");
}
break;
default:
printf("invalid choice=");
}
}
/*string handling function*/
ReplyDelete#include
#include
void main()
{
int choice,n=0;
char s[10],str1[10],str2[10];
printf("\n\t1.Length of string \n\t2.copy one string into another string \n\t3.string concatenation \n\t4.string comparation");
printf("\n\tEnter your choice ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n\tEnter a string");
scanf("%s",s);
printf("\n\tLength of string=%d",strlen(s));
break;
case 2:
printf("\n\tEnter First string");
scanf("%s",str1);
printf("\n\tEnter second string");
scanf("%s",str2);
printf("\n\tBefore copying first string=%s \n\tsecond string=%s",str1,str2);
strcpy(str1,str2);
printf("\n\tAfter copying first string=%s \n\t second string=%s",str1,str2);
break;
case 3:
printf("\n\tEnter First string");
scanf("%s",str1);
printf("\n\tEnter second string");
scanf("%s",str2);
strcat(str1,str2);
printf("\n\tAfter combining str1=%s \n\tstr2=%s",str1,str2);
break;
case 4:
printf("\n\tEnter First string");
scanf("%s",str1);
printf("\n\tEnter second string");
scanf("%s",str2);
n=strcmp(str1,str2);
if(n==0)
printf("\n\tTwo strings are equal");
else if(n>0)
printf("\n\tFirst string is greater");
else
printf("\n\tFirst string is small");
break;
default :
printf("\n\tInvalid case");
break;
}
}
/*string handling function*/
ReplyDelete#include
#include
void main()
{
int choice,n=0;
char s[10],str1[10],str2[10];
printf("\n\t1.Length of string \n\t2.copy one string into another string \n\t3.string concatenation \n\t4.string comparation");
printf("\n\tEnter your choice ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n\tEnter a string");
scanf("%s",s);
printf("\n\tLength of string=%d",strlen(s));
break;
case 2:
printf("\n\tEnter First string");
scanf("%s",str1);
printf("\n\tEnter second string");
scanf("%s",str2);
printf("\n\tBefore copying first string=%s \n\tsecond string=%s",str1,str2);
strcpy(str1,str2);
printf("\n\tAfter copying first string=%s \n\t second string=%s",str1,str2);
break;
case 3:
printf("\n\tEnter First string");
scanf("%s",str1);
printf("\n\tEnter second string");
scanf("%s",str2);
strcat(str1,str2);
printf("\n\tAfter combining str1=%s \n\tstr2=%s",str1,str2);
break;
case 4:
printf("\n\tEnter First string");
scanf("%s",str1);
printf("\n\tEnter second string");
scanf("%s",str2);
n=strcmp(str1,str2);
if(n==0)
printf("\n\tTwo strings are equal");
else if(n>0)
printf("\n\tFirst string is greater");
else
printf("\n\tFirst string is small");
break;
default :
printf("\n\tInvalid case");
break;
}
}
/*switch case of string handling function*/
ReplyDelete#include
#include
#include
void main()
{
int ch;
char s1[10];
char s2[10];int n;
printf("1.calculate length of string");
printf("\n2. copy one str into another\n3.string combin\n4.stirng compare");
printf("\n\t enter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\n\t enter string" );
scanf("%s",s2);
printf("\n\t str length=%d",strlen(s1));
break;
case 2: printf("\n\t enter str");
scanf("%s",s1);
printf("\n\t enter str");
scanf("%s",s2);
strcpy(s1,s2);
printf("after copy=%s",strcpy(s1,s2));
break;
case 3:printf("\n\t enter str");
scanf("%s",s1);
printf("\n\t enter str");
scanf("%s",s2);
strcat(s1,s2);
printf("after combin=%s",strcat(s1,s2));
break;
case 4: printf("\n\t enter str");
scanf("%s",s1);
printf("\n\t enter str");
scanf("%s",s2);
n=strcmp(s1,s2);
if(n=0)
{
printf("both str are equal");
}
if(n>0)
{
printf("s1 is greater");
}
if(n<0)
{
printf("s1 is small");
}
break;
default :printf("\n\t enter correct choice");
break;
}
}
/* string handling function */
ReplyDelete#include
#include
void main()
{
int choice ,a;
char str1[10],str2[10];
printf("\n1. length of string \n2.copy of string \n3.string concatination \n4. string comparision ");
printf("\nenter ur choice");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n enter string");
scanf("%s",str1);
printf("\n length of string=%d",strlen(str1));
break;
case 2:
printf("\nenter 1st string");
scanf("%s",str1);
printf("\n enter 2nd string");
scanf("%s",str2);
printf("\n after copy 1st string=%s 2nd string=%s",strcpy(str1,str2));
break;
case 3:
printf("\n enter 2 string");
scanf("%s%s",str1,str2);
printf("\n after concatination 1st string=%s 2nd string=%s",strcat(str1,str2));
break;
case 4:
printf("\nenter 2 string");
scanf("%s%s",str1,str2);
a=strcmp(str1,str2);
if(a==0)
printf("\nequal");
if(a>0)
printf("\n 1st string large");
if(a<0)
printf("\n 2nd string large");
break;
default :
printf("\n wrong choice");
break;
}
}
/* Program to implement string library functions */
ReplyDelete#include
#include
void main()
{
char s1[10],s2[10];
int i;
int choice;
printf("\n 1 for STRING COMPARE");
printf("\n 2 for STRING LENGTH ");
printf("\n 3 for STRING CONCATENATION ");
printf("\n Enter the choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter the string:");
scanf("%s",s1);
printf("\nEnter the string:");
scanf("%s",s2);
if(!strcmp(s1,s2))
printf("\nEqual");
else
printf("\nNot Equal");
break;
case 2:
printf("\nEnter the string:");
scanf("%s",s1);
i=strlen(s1);
printf("\nLength: %d",i);
break;
case 3:
printf("\nEnter the string:");
scanf("%s",s1);
printf("\nEnter the string:");
scanf("%s",s2);
strcat(s1,s2);
printf("\nString: %s",s1);
break;
default:
printf("\nWrong Option...");
}
}
/* string handling function */
ReplyDelete#include
#include
void main()
{
int choice ,a;
char str1[10],str2[10];
printf("\n1. length of string \n2.copy of string \n3.string concatination \n4. string comparision ");
printf("\nenter ur choice");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n enter string");
scanf("%s",str1);
printf("\n length of string=%d",strlen(str1));
break;
case 2:
printf("\nenter 1st string");
scanf("%s",str1);
printf("\n enter 2nd string");
scanf("%s",str2);
printf("\n after copy 1st string=%s 2nd string=%s",strcpy(str1,str2));
break;
case 3:
printf("\n enter 2 string");
scanf("%s%s",str1,str2);
printf("\n after concatination 1st string=%s 2nd string=%s",strcat(str1,str2));
break;
case 4:
printf("\nenter 2 string");
scanf("%s%s",str1,str2);
a=strcmp(str1,str2);
if(a==0)
printf("\nequal");
if(a>0)
printf("\n 1st string large");
if(a<0)
printf("\n 2nd string large");
break;
default :
printf("\n wrong choice");
break;
}
}
/*switch case of string handling function*/
ReplyDelete#include
#include
#include
void main()
{
int ch;
char s1[10];
char s2[10];int n;
printf("1.calculate length of string");
printf("\n2. copy one str into another\n3.string combin\n4.stirng compare");
printf("\n\t enter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\n\t enter string" );
scanf("%s",s2);
printf("\n\t str length=%d",strlen(s1));
break;
case 2: printf("\n\t enter str");
scanf("%s",s1);
printf("\n\t enter str");
scanf("%s",s2);
strcpy(s1,s2);
printf("after copy=%s",strcpy(s1,s2));
break;
case 3:printf("\n\t enter str");
scanf("%s",s1);
printf("\n\t enter str");
scanf("%s",s2);
strcat(s1,s2);
printf("after combin=%s",strcat(s1,s2));
break;
case 4: printf("\n\t enter str");
scanf("%s",s1);
printf("\n\t enter str");
scanf("%s",s2);
n=strcmp(s1,s2);
if(n=0)
{
printf("both str are equal");
}
if(n>0)
{
printf("s1 is greater");
}
if(n<0)
{
printf("s1 is small");
}
break;
default :printf("\n\t enter correct choice");
break;
}
}
/* string handling function */
ReplyDelete#include
#include
void main()
{
int choice ,a;
char str1[10],str2[10];
printf("\n1. length of string \n2.copy of string \n3.string concatination \n4. string comparision ");
printf("\nenter ur choice");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n enter string");
scanf("%s",str1);
printf("\n length of string=%d",strlen(str1));
break;
case 2:
printf("\nenter 1st string");
scanf("%s",str1);
printf("\n enter 2nd string");
scanf("%s",str2);
printf("\n after copy 1st string=%s 2nd string=%s",strcpy(str1,str2));
break;
case 3:
printf("\n enter 2 string");
scanf("%s%s",str1,str2);
printf("\n after concatination 1st string=%s 2nd string=%s",strcat(str1,str2));
break;
case 4:
printf("\nenter 2 string");
scanf("%s%s",str1,str2);
a=strcmp(str1,str2);
if(a==0)
printf("\nequal");
if(a>0)
printf("\n 1st string large");
if(a<0)
printf("\n 2nd string large");
break;
default :
printf("\n wrong choice");
break;
}
}
/*using string handling function*/
ReplyDelete#include
#include
void main()
{
int choice,n=0;
char s1[10],s2[10],s3[10];
printf("\n\t1.length of string\n\t2.copy one string into another string \n\t3.combine two string \n\t4.compair two string");
printf("\n\t enter your choice");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
printf("\n\t enter a string");
scanf("%s",s1);
strlen(s1);
printf("\n\t length of string=%d",s1);
break;
}
case 2:
{
printf("\n\t enter first string");
scanf("%s",s2);
printf("\n\t enter second string");
scanf("%s",s3);
strcpy(s2,s3);
printf("\n\t after copy first string=%s,second string=%s",s2,s3);
break;
}
case 3:
{
printf("\n\t enter first string");
scanf("%s",s2);
printf("\n\t enter second string");
scanf("%s",s3);
strcat(s2,s3);
printf("\n\t after combine s2=%s,s3=%s",s2,s3);
break;
}
case 4:
{
printf("\n\t enter first string");
scanf("%s",s2);
printf("\n\t enter second string");
scanf("%s",s3);
n=strcmp(s2,s3);
if(n==0)
{
printf("two string are equal");
}
else if(n>0)
{
printf("first string is large");
}
else
{
printf("first string is small");
}
break;
}
default:
printf("\n\t invalid choice");
break;
}
}
/* string handling function */
ReplyDelete#include
void main()
{
int choice ,a;
char str1[10],str2[10];
printf("\n1. length of string \n2.copy of string \n3.string concatination \n4. string comparision ");
printf("\nenter ur choice");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n enter string");
scanf("%s",str1);
printf("\n length of string=%d",strlen(str1));
break;
case 2:
printf("\nenter 1st string");
scanf("%s",str1);
printf("\n enter 2nd string");
scanf("%s",str2);
printf("\n after copy 1st string=%s 2nd string=%s",strcpy(str1,str2));
break;
case 3:
printf("\n enter 2 string");
scanf("%s%s",str1,str2);
printf("\n after concatination 1st string=%s 2nd string=%s",strcat(str1,str2));
break;
case 4:
printf("\nenter 2 string");
scanf("%s%s",str1,str2);
a=strcmp(str1,str2);
if(a==0)
printf("\nequal");
if(a>0)
printf("\n 1st string large");
if(a<0)
printf("\n 2nd string large");
break;
default :
printf("\n wrong choice");
break;
}
}
/* Program to implement string library functions */
ReplyDelete#include
#include
void main()
{
char s1[10],s2[10];
int i;
int choice;
printf("\n 1 for STRING COMPARE");
printf("\n 2 for STRING LENGTH ");
printf("\n 3 for STRING CONCATENATION ");
printf("\n Enter the choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter the string:");
scanf("%s",s1);
printf("\nEnter the string:");
scanf("%s",s2);
if(!strcmp(s1,s2))
printf("\nEqual");
else
printf("\nNot Equal");
break;
case 2:
printf("\nEnter the string:");
scanf("%s",s1);
i=strlen(s1);
printf("\nLength: %d",i);
break;
case 3:
printf("\nEnter the string:");
scanf("%s",s1);
printf("\nEnter the string:");
scanf("%s",s2);
strcat(s1,s2);
printf("\nString: %s",s1);
break;
default:
printf("\nWrong Option...");
}
}
/*string handling functions using switch case*/
ReplyDelete#include
#include
#include
//#include
void main()
{
int ch;
int l;
char source[100],target[100];
char *s,*t;
s=&source;
t=⌖
printf("\n*******************************MENU******************************");
printf("\n\t1.String length \n\t2.String copy \n\t3.String concatenation \n\t4.String comparison \n\t5.String uppercase \n\t6.String lowercase \n\t7.String reverse \n\t8.Exit");
printf("\n*****************************************************************");
printf("\n\tEnter the choice");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\n\tEnter a string:");
scanf("%s",source);
l=strlen(source);
printf("\n\tLength of entered string is=%d",l);
break;
case 2:
printf("\n\tEnter first string:");
scanf("%s",source);
printf("\n\tEnter second string:");
scanf("%s",target);
printf("\n\tBefore copy \n1.first string=%s \n2.Second string=%s",source,target);
strcpy(target,source);
printf("\n\tAfter copy \n\t1,First string=%s \n\t2.Second string=%s",source,target);
break;
case 3:
printf("\n\tEnter first string to concatenate:");
scanf("%s",source);
printf("\n\tEnter second string to concatenate:");
scanf("%s",target);
strcat(source,target);
printf("\n\tThe concatenated string is=%s",source);
break;
case 4:
printf("\n\tEnter first string:");
scanf("%s",source);
printf("\n\tEnter second string :");
scanf("%s",target);
if(strcmp(source,target)==0)
printf("\n\tBoth strings are equal");
else if(strcmp(source,target)>0)
printf("\n\t %s=String is greater",source);
else
printf("\n\t %s=String is greater",target);
break;
/*case 5:
printf("\n\tEnter a string:");
scanf("%s",source);
strupr(source);
printf("\n\tString in uppercase is=%s",source); //commented area must be used in windows turbo c
break;
case 6:
printf("\n\tEnter a string:");
scanf("%s",source);
strlwr(source);
printf("\n\tString in lowercase is=%s",source);
break;
case 7:
printf("\n\tEnter a string:");
scanf("%s",source);
strrev(source);
printf("\n\tThe reversed string is=%s",source);
break;*/
default:
//printf("\n\t Invalid Choice");
exit(0);
break;
}
}