RicardasSim icon

strdup

RicardasSim | PRO | 07/06/19 01:29:34 PM UTC | 0 ⭐ | 593 👁️ | Never ⏰ | []
C |

420 B

|

None

|

0 👍

/

0 👎

//-std=c99 -Wall -Wextra -Wpedantic -Wshadow
 
#define _POSIX_C_SOURCE 200809L
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h> 
  
int main() 
{ 
    char str1[] = "Testing"; 
  
    char* str2 = strdup(str1);  
  
    if(!str2)
    {
        printf("strdup error.\n");
        return 1;
    }
    
    printf("%s\n", str1);
    printf("%s\n", str2);
    
    free(str2);
    
    return 0; 
}

Comments