I have problem with pointers. In program I put all words in array foldersName[]
. All words in array are OK, when I print them, but I want to return array of pointers, for each word in array one pointer. My method is:
char** getTokens(char * path){
.
.//Getting tokens in array foldersName[];
.char foldersName[count][255];
.
char * tokens[actualCountOfFolders]; //How much folders in foldersName
int i;
for(i=0;i<count;i++){
tokens[i] = foldersName[i];
printf("Folders pointer %s \n",tokens[i]);
}
return tokens;
For example I have foldersName = {"C","Game","Halo 4","Map"}
.
But if I printf tokens[i]
, like I did in for
loop, it prints this {"C","Game","Halo 4","Map?"}
. How to fix it?
And can I do this, after calling function, in next code?
char ** tokens =(char **) malloc(sizeof(char)*actualCountOfFolders);
tokens = getTokens(path);
int i = 0;
for(i =0;i<actualCountOfFolders;i++){
printf("Folders %s \n",tokens[i]);
}