I'm doing a project that requires me to open a file and analyze it in some way. I've made an array of all the lines and right now I'm trying to send one of the lines to a function and to return a pointer value to an array that I'm building in the function. this is the code for the function
char** colornamepicker(char** userinput) {//stringRemoveNonAlphaNum is a diffrent function that cleans the string
char* ptr; ptr = 0;
char* Color = strtok_s(userinput, " \t", &ptr);
Color = stringRemoveNonAlphaNum(Color);
char* first_name = strtok_s(NULL, " \t", &ptr);
first_name = stringRemoveNonAlphaNum(first_name);
char* last_name = strtok_s(NULL, " \t", &ptr);
last_name = stringRemoveNonAlphaNum(last_name);
char** player[3];//this is the point when im bulding the array and the values are good.
player[0] = _strdup(Color);
player[1] = _strdup(first_name);
player[2] = _strdup(last_name);
return *player;//Im returing a pointer because that what worked with some of the problems in the main
}
and here is the part of the function from the main that doesn't work, im trying to print it again to see what happend.
main(){
...//bunch of irrelevant code that opens a file and turns every line to an array of strings
char** player_1 = colornamepicker(line[1]);
printf_s("\nnow its the time to see if everything worked");
printf_s("\n%s %s %s" ,player_1[0],player_1[1],player_1[2]);
free(player_1);
}
Thanks for the help !