#include <string.h>
|
char *
strndup (const char *str, size_t n); |
If insufficient memory is available, NULL is returned and errno is set to ENOMEM.
#include <string.h> #include <stdio.h> #include <stdlib.h> int main() { char* ptr; ptr = (char *)strndup("abcde",3); printf("Duplicated string %s\n",ptr); ptr = (char *)strndup("Hello Hi",5); printf("Duplicated string %s\n",ptr); free(ptr); return 0; }
Output
Duplicated string abc Duplicated string Hello
© 2005-2007 Nokia |