Advertisement
celynwalters

C strings bug

May 3rd, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void test(char **strArray);
  5.  
  6. int main()
  7. {
  8.     char **strArray;
  9.     test(strArray);
  10.     char *other = "why?"; //Removing this line causes segfault between "attempt" and "success"
  11. }
  12.  
  13. void test(char **strArray)
  14. {
  15.     int i;
  16.     printf("attempt\n");
  17.     *strArray = malloc(10*sizeof(char *));
  18.     printf("success\n");
  19.     for (i=0; i<10; i++)
  20.         strArray[i] = malloc(3*sizeof(char));
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement