1] gets() :
▪️ The function gets() receives the string from an input device.
▪️ At the end string, the function gets() appends a null character.
▪️ The gets() function takes the following from:
gets(str);
▪️ Example:
void main()
{
char str[80];
printf( "Enter your name ");
gets(str);
printf(" Welcome ! %s",str);
}
Output:
Enter your name
Sky Eagle
Welcome ! Sky Eagle
2] strlen() function:
▪️ This function returns length of string passing to it.
3 Hence it returns an integer value that must be collected within a variable .
4 It takes the following gereral format.
L = strlen ( str );
Example:
#include<stdio.h>
#include<string.h>
Void main()
{
char str[ ]="Hello friends";
int length;
length=strlen(str);
Printf("length of string=%d",length);
}
Output:
length of string = 6
3] strcpy() function:
▪️ This function copies one string in to another string variable.
▪️ the base address of source string and target string should be supplied to function.
▪️ The source string remains as it is , while target string will be changed.
▪️ The general form of strcpy() is
L = strcpy(targetstring, sourcestring);
▪️ Example:
#include<string.h>
void main()
{
char target[10]="Bad",source[10]="Good";
strcpy(target,source);
printf("target string=%s",target);
}
Output:
target string = Good
4] strncpy() function:
▪️ This function copies starting N characters from the source string to target string .
▪️ The base address of source string and target string should be supplied to function.
▪️ The general form of strncpy() is
Strncpy(target string, source string ,N)
Example:
#include<stdio.h>
#include<string.h>
void main()
{
char target [20],source[20]="Happy Birthday";
strncpy(target,source,5);
printf("target string=%s",target);
}
Output:
target string = Happy
Informative but use smartphone friendly themes
ReplyDeleteCkeck mine
https://vcarskill2020.blogspot.com/2020/09/kia-sonet-review.html?m=1
https://vcarskill2020.blogspot.com/2020/09/toyota-urban-cruiser.html?m=1