fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int create(char ***array);
  6.  
  7. int main() {
  8. char **list;
  9. create(&list);
  10. int i = 0;
  11. for (i = 0; i < 2; i++)
  12. printf("%s\n",list[i]);
  13.  
  14.  
  15. }
  16.  
  17. int create(char ***array) {
  18.  
  19. char* str[] = { "hello", "dear" };
  20. int len;
  21. int i = 0;
  22. *array = malloc(2 * sizeof(char*));
  23. for (i = 0; i < 2; i++) {
  24. len = strlen(str[i]);
  25. printf("%d\n", len);
  26. ( *array)[i] =malloc(len * sizeof(char*)+1);
  27. strcpy((*array)[i], str[i]);
  28. //printf("%s\n", array[i]); // this prints
  29. }
  30. return 1;
  31. }
Success #stdin #stdout 0s 2288KB
stdin
Standard input is empty
stdout
5
4
hello
dear