RicardasSim

strdup

Jul 6th, 2019
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. //-std=c99 -Wall -Wextra -Wpedantic -Wshadow
  2.  
  3. #define _POSIX_C_SOURCE 200809L
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. int main()
  10. {
  11.     char str1[] = "Testing";
  12.  
  13.     char* str2 = strdup(str1);  
  14.  
  15.     if(!str2)
  16.     {
  17.         printf("strdup error.\n");
  18.         return 1;
  19.     }
  20.    
  21.     printf("%s\n", str1);
  22.     printf("%s\n", str2);
  23.    
  24.     free(str2);
  25.    
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment