#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
const char* getfield(char* line, int num)
{
const char* tok;
tok && *tok;
{
if (!--num)
return tok;
}
return NULL;
}
int main()
{
char line[1024];
while (fgets(line
, 1024, stdin
)) {
char* tmp = strdup(line);
printf("Field 3 would be %s\n", getfield
(tmp
, 3)); // NOTE strtok clobbers tmp
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8ZXJybm8uaD4KCmNvbnN0IGNoYXIqIGdldGZpZWxkKGNoYXIqIGxpbmUsIGludCBudW0pCnsKCWNvbnN0IGNoYXIqIHRvazsKCWZvciAodG9rID0gc3RydG9rKGxpbmUsICI7Iik7CgkJCXRvayAmJiAqdG9rOwoJCQl0b2sgPSBzdHJ0b2soTlVMTCwgIjtcbiIpKQoJewoJCWlmICghLS1udW0pCgkJCXJldHVybiB0b2s7Cgl9CglyZXR1cm4gTlVMTDsKfQoKaW50IG1haW4oKQp7CgljaGFyIGxpbmVbMTAyNF07CiAgICB3aGlsZSAoZmdldHMobGluZSwgMTAyNCwgc3RkaW4pKQoJewoJCWNoYXIqIHRtcCA9IHN0cmR1cChsaW5lKTsKCQlwcmludGYoIkZpZWxkIDMgd291bGQgYmUgJXNcbiIsIGdldGZpZWxkKHRtcCwgMykpOwoJCS8vIE5PVEUgc3RydG9rIGNsb2JiZXJzIHRtcAoJCWZyZWUodG1wKTsKCX0KfQo=
bHA7aW1pZTtuYXp3aXNrbzt1bGljYTtudW1lcjtrb2Q7bWllanNjb3dvc2M7dGVsZWZvbjtlbWFpbDtkYXRhX3VyCjE7SmFuO0tvd2Fsc2tpO3VsLiBOb3dhOzFhOzExLTIzNDtCdWRyeTsxMjMtMTIzLTQ1NjtqYW5AZ28ueHh4OzE5ODAuMDUuMTMKMjtKZXJ6eTtOb3dhazt1bC4gS29ub3BuaWNrYTsxM2EvMzswMC05MDA7TGljaG93aWNlOyg1NSkzMzMtNDQtNTU7amVyQHd1LnRvOzE5OTAuMDMuMjM=
lp;imie;nazwisko;ulica;numer;kod;miejscowosc;telefon;email;data_ur
1;Jan;Kowalski;ul. Nowa;1a;11-234;Budry;123-123-456;jan@go.xxx;1980.05.13
2;Jerzy;Nowak;ul. Konopnicka;13a/3;00-900;Lichowice;(55)333-44-55;jer@wu.to;1990.03.23