Wednesday, October 3, 2018

CPL 10 - STRING OPERATIONS

10. Write functions to implement string operations such as compare, concatenate, string length. Convince the parameter passing techniques.

Algorithm:

Step 1: Start
Step 2: read two strings
Step 3: calculate the string length using strlen()
Step 4: compare the string using strcmp()
Step 5: concatenate the strings using strcat()
Step 6: print the stringlength
Step 7: print strings are equal or not equal
Step 8: print concatenated sting

Step 9: stop

FLOWCHART: ( WILL BE UPDATED SOON)

PROGRAM:

#include<stdio.h>
#include<string.h>

void stringlength(char a[100],char b[100]);
void concatenate(char a[100],char b[100]);
void stringcompare(char a[100],char b[100]);

void main()
{
char p[100],q[100],ch[100];
int len1,len2;
printf("Enter the first string:\n");
gets(p);
printf("Enter the second string:\n");
gets(q);
stringlength(p,q);
stringcompare(p,q);
concatenate(p,q);
}

void stringlength(char a[100], char b[100])
{
int len1,len2;
len1=strlen(a);
len2=strlen(b);
printf("First string length is :%d \nSecond string lenght is: %d",len1,len2);
}

void concatenate(char a[100], char b[100])
{
printf("The concatenated String is :%s ", strcat(a,b));
}

void stringcompare(char a[100], char b[100])
{
if(strcmp(a,b)==0)
printf("\nSTRINGS ARE EQUAL\n");
else
  printf("\nSTRINGS ARE NOT EQUAL\n");

}

OUTPUT:

1 comment: