i got a txt file write like this:
T,G,F,F
G,T,T,F
G,T,F,G
T,F,G,T
dimen = 4
and i want to import it into array,as dynamic allocating of chars like:
[T,G,F,F,G,T,T,F,G,T,F,G,T,F,G,T]
i tried the code beyond but i got an error.
void file_2_arr(FILE *file,char *forest_current,int dimen)
{
int i = 0;
char *buffer = NULL;
buffer =(char*)malloc(sizeof(char) * (2*dimen-1));
const char* delim = ",";
while (!feof(file))
{
fgets(buffer, sizeof buffer, file);
char* token = strtok(buffer, delim);
while (token != NULL)
{
printf("%s", token);
strcpy(forest_current, token);
token = strtok(NULL, delim);
forest_current++;
}
}
free(buffer);
return;