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

string

String coding

Uploaded by

priyajenat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

string

String coding

Uploaded by

priyajenat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Strlen()

This method returns the length of the given input string.

It won't count the terminating null character.

Syntax:

length=strlen(string);

Example:

#include<studio.h>

#include<string.h>

void main()

int length;

char S1[50];

printf("Enter string:");

scanf("%s", S1);

length=strlen(S1);

printf("length of %s is:%d",S1,length);

getch();

Output:

Enter string: welcome

length of welcome is:7

strcpy():
This method copies the content of one string to another string.

Syntax:

strcpy(s1,s2);

This will copy contents of s2 to s1.

Example:

#include<studio.h>

#include<string.h>

void main()

char S1[50],S2[50];

printf("Enter string:");

scanf("%s", S1);

strcpy(S2,S1);

printf("original string is:%s",S1);

printf("copied string:%s",S2);

getch();

Output:

Enter string: welcome

original string: welcome

copied string: welcome

strcat():

This method concatenates (mergers/joins) two user input strings.


Syntax:

strcat(S1,S2);

Example:

#include<studio.h>

#include<string.h>

void main()

char S1[50],S2[50];

printf("Enter string1:");

scanf("%s", S1);

printf("Enter string2:");

scanf("%s", S2);

strcat(S2,S1);

printf("concatenated string:%s",S2);

getch();

Output:

Enter string1: hello

Enter string2: welcome

concatenated string: hellowelcome

You might also like