If I'm reading in lines from a .txt file of varying length, (i.e. 5 integers on line 1, then 2 integers on line 2, then 10 integers on line 3, and etc.), using fgets (although I don't necessarily need to use it, just seemed like a good tool in my situation). Every solution I find returns an error of 0 (like strtol or atio).
char str[100];
char* p = str;
FILE* fp;
fp = open("text.txt",r);
if(fp == NULL)
printf("aborting.. Cannot open file! \n");
while(!foef(fp))
{
if(fgets(p,100,fp) != NULL)
{
for (int j = 0 ; j < 20 ; j+=2)
{
temp1 = strtol(p, &p, 10);
// need to store temp1 into arr[j] if it is a valid integer (0->inf)
// but should discard if we are at the end of the line
}
}