strdup() function-This function is used for duplicating the string at allocated memory which is pointed by a pointer variable.
syntax
dup1=strdup(s1) ,where s1 is string and dup1 is pointer
Write a program to enter a string and get its duplicate with strdup() function.
#include<stdio.h>
#include<conio.h>
main()
{
char string[10],dup1[10];
clrscr();
printf("Enter the string:");
gets(string);
dup1=strdup(string)
printf("\n Original string %s \n Duplicate string %s:",string,dup1);
}
Output
Enter the string:Good Day
Original string Good Day
Duplicate string Good Day
syntax
dup1=strdup(s1) ,where s1 is string and dup1 is pointer
Write a program to enter a string and get its duplicate with strdup() function.
#include<stdio.h>
#include<conio.h>
main()
{
char string[10],dup1[10];
clrscr();
printf("Enter the string:");
gets(string);
dup1=strdup(string)
printf("\n Original string %s \n Duplicate string %s:",string,dup1);
}
Output
Enter the string:Good Day
Original string Good Day
Duplicate string Good Day
No comments:
Post a Comment