Note that there are some explanatory texts on larger screens.

plurals
  1. POstring tokenizer in c until tab and newline
    primarykey
    data
    text
    <p>I have some problem when I want to tokenize the text below and to save tokens in a struct.</p> <pre><code>Wojciech Szczęsny POL G 1.95 84 18-04-90 Warsaw Legia Warszawa Bacary Sagna FRA D 1.76 72 14-02-83 Sens Auxerre Per Mertesacker GER D 1.98 90 29-09-84 Hannover Werder Bremen </code></pre> <p>Bewtween words is one space and one tab, and I would like to give the following:</p> <pre><code>t[1].nev = Wojciech Szczesny t[1].orsz = POL t[1].poz = G t[1].mag = 1.95 t[1].suly = 84 t[1].datum = 18-04-90 t[1].varos = Warsaw t[1].ecs = Legia Warszawa and etc. </code></pre> <p>I did not edit the txt file because it contains more than 20,000 data.</p> <p>my code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;conio.h&gt; typedef struct{ char nev[50]; char orsz[3]; char poz[3]; float mag; int suly; char datum[10]; char varos[30]; char ecs[50]; }JATEKOS; int main(){ FILE*f=fopen("Text.txt","rt"); int i; JATEKOS*t; t = (JATEKOS*)malloc(3*sizeof(JATEKOS)); for(i=1;i&lt;=2;++i){ fscanf(f,"%[^\t]",t[i].nev); fscanf(f,"%[^\t]",t[i].orsz); fscanf(f,"%[^\n]",t[i].poz); fscanf(f,"%[^\t]",&amp;t[i].mag); fscanf(f,"%[^\t]",&amp;t[i].suly); fscanf(f,"%[^\t]",t[i].datum); fscanf(f,"%[^\t]",t[i].varos); fscanf(f,"%[^\n]",t[i].ecs); } printf("\n\n"); for(int i=1;i&lt;=2;++i){ //printf("%s %s %s %f %i %s %s %s",t[i].nev,t[i].orsz,t[i].poz,t[i].mag,t[i].suly,t[i].datum,t[i].varos,t[i].ecs); printf("%s %s %s",t[i].nev,t[i].orsz,t[i].poz); } getch(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload