Full Disclosure: This is part of an assignment I have received from school. In the assignment we are forbidden to use fscanf().
I have been trying to get this to work, but I've started to realize that I do not have a complete understanding of what strtok() actually does. I'm getting this warning when debugging: "assignment makes integer from pointer without cast."
This warning happens when assigning str to goal and assist, and I think it is because they are, when dereferenced, integers. The code below correctly assigns the name into the correct spot, but leaves nonsense data in the goal and assist arrays. ex:-7880, -7888
file example:
NAME GOALS ASSISTS
JOHN 1 2
Code:
void readLinesFromFile( FILE* Ptr, int* goal, int* assist, char** name, int lines ){/*
* Reads lines from files and populates the arrays with the corresponding info.
*/
int index;
char hold[ MAX_LINE ] = { 0 };
char* str = NULL;
for( index = 0; index < lines; index++ ){
fgets( hold, MAX_LINE, Ptr );
str = strtok( hold, " " );
*( name + index ) = str;
str = strtok( NULL, " " );
*( goal + index ) = str;
str = strtok( NULL, " " );
*( assist + index ) = strtok( hold, " " );
}//endfr
}//endfn
From what I understand about strtok(), it returns a string, and takes in a character array and a key value that tells it when to stop. In the online examples I've seen, they use NULL in the first field. I'm not sure why. I've read the definition on this site and I'm just missing some understanding about the function. I'd appreciate any help that could be provided.