71. WRITE A C PROGRAM USING STRING HANDLING FUNCTIONS

a)strlenb)strcpyc)strcatd)strcmp

a) /*C program using string handling functions*/

a)strlen
b)strcpy
c)strcat
d)strcmp
a)strlen(to find length of a string)
#include<stdio.h>
#include<conio.h>
int main()
{
char str[20];
int length ;
printf("\nEnter the String : ");
gets(str);
length = strlen(str);
printf("\nLength of String : %d ", length);
getch();
return 0;
}

output

enter the string
kucet
length of string : 5

b) /*C Program to Copy one string into other with using library function*/

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

int main() {
char str1[100];
char str2[100];

printf("\nEnter the String 1 : ");
gets(str1);

strcpy(str2, str1);
printf("\nCopied String : %s", str2);

return (0);
}

output

Enter the String 1 : kucet
Copied String : kucet


c) /*C Program to Concat Two Strings with using Library Function*/
#include <stdio.h> 
#include <string.h> 
int main() 

char a[100], b[100]; 
printf("Enter the first string\n"); gets(a); printf("Enter the second string\n"); gets(b); strcat(a,b); printf("String obtained on concatenation is %s\n",a); 
return 0; 
}

output

enter the first string
KUCET_
enter the second string
IT
string obtained on catenation is KUCET_IT

d)/*c program to compare two strings*/ 

#include<stdio.h> 
#include<string.h> 
int main() 
{ char a[100], b[100]; 
printf("Enter the first string\n"); gets(a); printf("Enter the second string\n"); gets(b); 
if( strcmp(a,b) == 0 ) 
printf("Entered strings are equal.\n"); 
else 
printf("Entered strings are not equal.\n"); 
return 0; 
}

output

enter the first string
KUCET
enter the second string
KUCET
entered strings are equal

Comments