I am trying to retain the value of array1_ptr[i] between the calls in different files i.e. test.c and testfunc.c. But it is not retaining the value in next call
file: test.h
extern char** array1_ptr;
void change_ptr1(int i); //to fill the values in array1_ptr
void memalloc();
file: test.c
#include "test.h"
char** array1_ptr;
int main()
{
int i;
memalloc();
for(i = 0; i < 10; i++)
{
change_ptr1(i);//calling the function whose definition in other file
}
return 0;
}
file: testfunc.c
#include "test.h"
void change_ptr1(int i)
{
array1_ptr[i] = i + 1; //filling the values which are not retained in next call
}
void memalloc()
{
int i;
array1_ptr = (char**)malloc(10 * sizeof(char*));
for(i = 0; i < 10; i++)
array1_ptr[i] = (char*)malloc(10 * sizeof(char));
}