Hello, I have the following code below:
Code:
#include <ansi_c.h>
#include<stdio.h>
int main(void)
{
FILE *in;
int size;
char *data;
char *tokenPtr;
in=fopen("filename.txt","r");
fseek(in,0,SEEK_END);
size=ftell(in);
rewind(in);
data=(char*)malloc(size*sizeof(char));
fread(data,sizeof(char),size,in);
fclose(in);
tokenPtr=strtok(data,",");
while(tokenPtr != NULL)
{
printf("%s\n",tokenPtr);
tokenPtr = strtok(NULL, ",");
}
free(data);
return(0);
}
When I try to run the code, it gives me the following error: "Missing terminating null in string argument."
Any ideas on how to fix this issue?
Thanks!