#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
const char* getfield(char* line, int num)
{
const char* tok;
for (tok = strtok(line, ";");
tok && *tok;
tok = strtok(NULL, ";\n"))
{
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
free(tmp);
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8ZXJybm8uaD4KCmNvbnN0IGNoYXIqIGdldGZpZWxkKGNoYXIqIGxpbmUsIGludCBudW0pCnsKCWNvbnN0IGNoYXIqIHRvazsKCWZvciAodG9rID0gc3RydG9rKGxpbmUsICI7Iik7CgkJCXRvayAmJiAqdG9rOwoJCQl0b2sgPSBzdHJ0b2soTlVMTCwgIjtcbiIpKQoJewoJCWlmICghLS1udW0pCgkJCXJldHVybiB0b2s7Cgl9CglyZXR1cm4gTlVMTDsKfQoKaW50IG1haW4oKQp7CgljaGFyIGxpbmVbMTAyNF07CiAgICB3aGlsZSAoZmdldHMobGluZSwgMTAyNCwgc3RkaW4pKQoJewoJCWNoYXIqIHRtcCA9IHN0cmR1cChsaW5lKTsKCQlwcmludGYoIkZpZWxkIDMgd291bGQgYmUgJXNcbiIsIGdldGZpZWxkKHRtcCwgMykpOwoJCS8vIE5PVEUgc3RydG9rIGNsb2JiZXJzIHRtcAoJCWZyZWUodG1wKTsKCX0KfQo=
bHA7O25hendpc2tvO3VsaWNhO251bWVyO2tvZDttaWVqc2Nvd29zYzt0ZWxlZm9uO2VtYWlsO2RhdGFfdXIKMTtKYW47S293YWxza2k7dWwuIE5vd2E7MWE7MTEtMjM0O0J1ZHJ5OzEyMy0xMjMtNDU2O2phbkBnby54eHg7MTk4MC4wNS4xMwoyO0plcnp5O05vd2FrO3VsLiBLb25vcG5pY2thOzEzYS8zOzAwLTkwMDtMaWNob3dpY2U7KDU1KTMzMy00NC01NTtqZXJAd3UudG87MTk5MC4wMy4yMw==
lp;;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