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

L9_corrected

Uploaded by

shreeumaluti
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)
11 views

L9_corrected

Uploaded by

shreeumaluti
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/ 1

1.

L9) Write functions to implement string operations such as compare, concatenate, string
length. Convince the parameter passing techniques.
/* UDFs to compare, concatenate, find length /* UDFs */
of string */ int s_length(char s1[])
#include<stdio.h> {
int main() int i;
{ for(i=0; s1[i]!='\0';i++)
int s_length(char s1[]); {
int s_compare(char s1[],char s2[]); ;
void s_concat(char s1[],char s2[], int len1); }
char s1[20], s2[20]; return(i);
int len1, len2, flag; }
printf("UDFs to compare, concat, find len: \n");
printf("Enter string-1:"); int s_compare(char s1[], char s2[])
scanf("%s",s1); {
printf("Enter string-2: "); int i;
scanf("%s",s2); for(i=0; s1[i]!='\0';i++)
{
/*function call of s_length*/ if(s1[i]!=s2[i])
len1=s_length(s1); {
len2=s_length(s2); return(1);
printf("Length of string-1: %d \n",len1); }
printf("Length of string-2: %d \n",len2); }
return(0);
/*function call of s_compare*/ }
flag=s_compare(s1,s2); void s_concat(char s1[],char s2[], int len1)
if(flag==0) {
printf("input strings are same \n"); int i = len1, j;
else for(j=0; s2[j] != '\0'; j++)
printf("Input strings are not same \n"); {
s1[i]=s2[j];
/*function call of s_concat*/ i++;
s_concat(s1, s2, len1); }
printf("After concatenation: %s",s1); s1[i]='\0';
} }

You might also like