title: Reading text line by line and word by word. C programming
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #define KIEK 100
  #define MAXSTRING 255
  
  int main()
  {
       int i=0, l;
       char line[MAXSTRING], duom[12], rez[12], wrd[MAXSTRING], lastchar,e;
       FILE *f, *r;
  
       puts("Iveskite ivesties failo varda:");
       scanf( "%s", duom);
       if (( f = fopen (duom, "r")) == NULL)
           printf("Negalima atverti failo \"%s\"\n ", duom);
       else
       {
           puts("Iveskite isvesties failo varda:");
           scanf("%s", rez);
           if((r = fopen (rez, "w")) == NULL)
               printf("Negalima sukurti rezultato failo \"%s\"\n ", rez);
           else
           {
               fgets(line, MAXSTRING, f);
               printf("%s",line);
  
               do
               {
                   e = sscanf(line, "%s", wrd);
                   printf("%s",wrd);
                   l = strlen(wrd);
                   i = i+l;
                   lastchar = line[i];
                   printf("%c%d",lastchar,i);
              }
              while(lastchar != '\n');
          }
          fclose(f);
          fclose(r);
      }
  }
  </code></pre>
  
  <p>What this should do is to read line from a text file, for example:</p>
  
  <pre>apples and oranges
  
  i love trains
  </pre>
  
  <p>This is not working.</p>
  
  <p>And then it should read each individual word until it finds the <code>\n</code> symbol. But it always reads the first one. What should I do?</p>