Advertisement
Guest User

Untitled

a guest
Dec 19th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <string.h>
  4.  
  5. char strings[3][8] = {"str1\n\0\0\0", "str12\n\0\0", "str123\n\0"};
  6.  
  7. int main()
  8. {
  9.     char** str_arr = malloc(sizeof(char*) * 3);
  10.     for (int i = 0; i < 3; i++)
  11.     {
  12.         str_arr[i] = malloc(sizeof(char) * 8);
  13.         memcpy(str_arr[i], strings[i], 8);
  14.     }
  15.     for (int i = 0; i < 3; i++)
  16.     {
  17.         printf(str_arr[i]);
  18.         free(str_arr[i]);
  19.     }
  20.     return 0;
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement