I am trying to pass a pointer to a function.In this function i use malloc to reserve space.The problem is that when i return in main the program doesn't respond.Here is my symplified code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int def(char **B){
int i;
B = malloc(3 * sizeof( char ));
for(i = 0; i < 2 ; i++){
B[i] = malloc(5 * sizeof(char));
}
for(i = 0; i < 2 ; i++){
scanf("%s" , B[i]);
}
for(i = 0; i < 2 ; i++){
printf("%s\n" , B[i]);
}
return 0;
}
int main(int argc, char *argv[]) {
char **B;
int i;
def(B);
for(i = 0; i < 2 ; i++){
printf("%s\n" , B[i]);
}
return 0;
}