I'm going back to C at my University a year of Java, and our first assignment is to read the values present in a .CSV file, but the textbook isn't clear and the prof hasn't helped us much. I really don't have a lot of direction on this, and the assignment is due soon, so I really need some direction!
I think I can get through most everything myself, but I'm just not certain what this block of code does...
static int extractItems(char *line, char row[][MAXLEN]) {
char *item;
int col = 0;
for( ; ; ) {
item = strtok(line, ",\r\n");
if (item == NULL)
break;
if (col >= MAXCOLS) {
tooWide = 1;
break;
}
strncpy(row[col], item, MAXLEN);
row[col][MAXLEN] = '\0'; // force null termination
col++;
line = NULL; // required by strtok function
}
return col;
}
Col refers to the column number, the first being 0.
I understand that it checks if there is nothing in the line and whether it's too wide, but the rest is foreign to me.