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

String Function

Uploaded by

khatuasourav00
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

String Function

Uploaded by

khatuasourav00
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

strlen( )

C Program To Count Length Of String Using Library Function

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

void main() {
char str[100];
int len;

printf("\nEnter the String : ");


scanf("%s",str);

/*
strlen() is the pre-defined function
to find the length of a string
*/
len = strlen(str);

printf("\nLength of the given string is %d", len);

2. strcpy( )

C Program To Count copy one String to another Using Library Function

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

void main()
{
char string1[]="Hello";
char string2[]="World";

printf("String-1 before strcpy() function : %s",string1);


strcpy(string1,string2);
printf("\nString-1 after strcpy() function : %s",string1);

}
3. strcat( )

C Program for concatenation of two String Using Library Function

#include <stdio.h>
#include<string.h>
void main()
{
//Declaring the value of str1 and str2
char str1[50] = "Coding";
char str2[50] = "Ninjas";
strcat (str1, str2); //performing the function
printf("%s", str1); //printing the value of str1

4. strcmp( )

C Program for comparing two String Using Library Function

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

void main()
{
char string1[]="Ninja";
char string2[]="Ninja";

int val=strcmp(string1,string2);
printf("On comparing %s and %s the value returned is %d",string1,string2,val);

You might also like