Code:
int main(int argc, char* argv[])
{
FILE* input;
const char input_fn[]="proj3input.dat";
char linebuf[1025];
char *tokptr, *strptr = linebuf;
int col=0, line_num=0;
input=fopen("proj3input.dat","r");
while((fgets(linebuf, 1024, input) != NULL))
line_num++;
printf("Number of lines is %d \n", line_num);
while((tokptr=(char*)strtok(strptr, " \t")) != NULL);
{
printf("DATA: %s\n",tokptr); fflush(stdout);
strptr = NULL;
col++;
}
printf("Number of columns is %d \n", col);
return(0);
}
This prints "Number of lines is 10000" Then hangs on new line. I will have a look at the strtok() again in more detail, but I couldn't see anything wrong at first glance.
Is there any other way of counting the columns?