strdup(): Duplicating string

#include <stdio.h>
#include <string.h>
int main()
    char str1[] = "plus2net";
    char *str2;
    str2 = strdup(str1);

    printf("Duplicated string : %s", str2);
    return 0;
The output of above code is here
Duplicated string : plus2net
We can duplicate a string by using strdup() string function.
duplicate_string = strdup(main_string);
Output is pointer of duplicate_string.


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer