pointer arrays to function: can't copy strings

Hello,

This is the fisrt time ever that I post a question on the net.
The code is in C. I don't know C++.

I'm trying to pass a array of "char* pTab[NBR_LINE]" to a function, copy strings from a text file in the array "ReadListFile()". And then use the array of strings in other functions.

I have asked people, looked on the net, and looked in C in a nutshell (page.135).

I have two problems:

1) strcpy(*pTab+i,line); //access violation
2) Can't access the strings back in the main, if I do *pTab[i] = line

Would anybody know the answer to my problem?

/********************************************/
#define TRAIN 1
#define NBR_LINE 1400


int main(void){

char* pTab[NBR_LINE]= {NULL};

ReadListFile(TRAIN, pTab);
for(...;...;...){
printf("final pTab[i] = &pTab[i] = %X %s\n",&pTab[i], pTab[i])
}

system("PAUSE");
return EXIT_SUCCESS;
}
/***********************/
extern void ReadListFile(const char OpMode, char **pTab){

int i = 0;
char line[200];
FILE * pListFile ;

//... more stuff here
pListFile = fopen("..\\..\\info_train.txt","r");
//... more stuff here, functionnal

for(i=0; !feof(pListFile); i++){
fgets (line, 200, pListFile);
strcpy(*pTab+i,line);
}
if(fclose(pListFile)!=0) perror("Error closing file");
}
/*****************************/
It might be because you are referencing a variable that belongs to main.
Try moving your definition of pTab outside of main (I.E. at the global scope).. right above main will do

Let us know if that doesn't work.

Also, next time you post (on any codeing forum, not just this one), be sure to use the code tags when posting code.
I don't see where you're allocating memory anywhere.
strcpy(*(pTab+i),line);
or
strcpy(pTab[i],line);
Ah wow, you know what, peter is right. I didn't catch that.
Thank you guys!!

allocation of memory & proper strcpy() helped.
Topic archived. No new replies allowed.