Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (void)
{
FILE *f;
char *s, *t;
int i, j;
f = fopen("tabela", "r");
i = 1;
while (!feof(f)) {
s = (char *) malloc(1025);
fgets(s, 1024, f);
s[strlen(s) - 1] = 0;
if (!strlen(s)) {
break;
}
j = 1;
while (t = strsep(&s, "\t")){
printf("Red %d; Token %d: '%s'\n", i, j++, t);
}
printf("\n");
i++;
}
fclose(f);
}
Fajl "tabela":
Code:
polje1 polje2 polje3
polje1 polje3
Output:
Code:
Red 1; Token 1: 'polje1'
Red 1; Token 2: 'polje2'
Red 1; Token 3: 'polje3'
Red 2; Token 1: 'polje1'
Red 2; Token 2: ''
Red 2; Token 3: 'polje3'
Marko.