0% found this document useful (0 votes)
16 views

Assignment 3

This C program allows the user to select from 5 string operations: 1) print string length, 2) reverse string, 3) copy string, 4) compare two strings, 5) concatenate two strings. It defines a function to calculate string length and uses a switch statement to call the appropriate function based on the user's selection.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Assignment 3

This C program allows the user to select from 5 string operations: 1) print string length, 2) reverse string, 3) copy string, 4) compare two strings, 5) concatenate two strings. It defines a function to calculate string length and uses a switch statement to call the appropriate function based on the user's selection.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

#include<stdio.

h>
#include<conio.h>
int length(char b[50])
{
int len,i;
for(i=0;b[i]!='\0';i++)
{
len=len+1;
}
return len;
}
int main()
{
int s;
char a[50];
printf("Enter String=");
scanf("%s",a);
printf("\n1:Print String length");
printf("\n2:Reverse String");
printf("\n3:Copy String");
printf("\n4:Compare String");
printf("\n5:Concatenate String");
printf("\nEnter Your Choice=");
scanf("%d",&s);

switch(s)
{
case 1 :
{
int l=length(a);
printf("\nString Length=%d",l);
break;
}
case 2 :
{
int l=length(a),i;
for(i=l-1;i>=0;i--)
{
printf("\n%c",a[i]);
}
break;
}
case 3 :
{
int l=length(a),i;
char c[50];
for(i=0;i<l;i++)
{
c[i]=a[i];
}
printf("\nString Copied in Another
Array 'c' is=%s",c);
break;
}
case 4 :
{
int i=0,flag=0;
int l=length(a);
char d[50];
printf("\nEnter Another String to be
Compared=");
scanf("%s",d);
for(i = 0; a[i] == d[i] && a[i] == '\0';
i++);
{
if(a[i] < d[i])
{
printf("\n%s is Less than %s",a,d);
}
else if(a[i] > d[i])
{
printf("\n %s is Less than %s",d,a);
}
else
{
printf("\n %s is Equal to %s",a,d);
}
}
break;
}
case 5 :

{
int l=length(a),i,j=0,k;
char e[50],f[100];
printf("\nEnter String to be
Concatenated =");
scanf("%s",e);
for(i=0;i<l;i++)
{
f[i]=a[i];
j++;
}
for(k=0;e[k]!=0;k++)
{
f[j]=e[k];
j++;
}
printf("\nConcatenated String
=%s",f);
break;
}
default:
printf("\nEnter Correct Choice!!");
}
}

You might also like