- strdup( ) function in C duplicates the given string. Syntax for strdup( ) function is given below.
char *strdup(const char *string);
- strdup( ) function is non standard function which may not available in standard library in C.
Example program for strdup() function in C:
- In this program, string “Raja” is duplicated using strdup( ) function and duplicated string is displayed as output.
#include <stdio.h>
#include <string.h>
int main()
{
char *p1 = "Raja";
char *p2;
p2 = strdup(p1);
printf("Duplicated string is : %s", p2);
return 0;
}
Output:
Duplicated string is : Raja
|






0 comments:
Post a Comment