Question: Hello I wrote this code for following question:
Write a C program that reads a text file into an array of character. You may assume that the file contains no more than 1000 characters. But code prints only first character of text. Where do I make mistake? 

```
FILE *wse;
char a[1000];
int i;

    wse=fopen("21e.txt","r");

    for(i=0;i!=100;i++);
    {
    fscanf(wse,"%c",&a[i]);
    printf("%c",a[i]);
    }

```

Answer: 
Your code has a *logical* error which makes it broken - very easy to fix.

* Your for loop has *empty body* - that's why it only prints the first character. *Semicolon* deleted.

There is also a style issue in checking the value of the counter:

* Although *checking* `i` against *not* being `100` won't make your code fail if everything else is OK, it's more common and conforming to your task specification to check its value for being *less than* `100`, or whichever constant you want.

Although this may not be the most elegant way of completing such a task, it's a rework of your read-by-character method code:

```
#include <stdio.h>

int main(void)
{
 FILE *wse;
 char a[1000];
 int i;

  if((wse=fopen("3.txt","r")) == NULL)//always check for file errors!
      return 1;

  for( i=0 ; i<100 ; i++ )
  {
      if(fscanf(wse,"%c",&a[i]) != 1) //check against end of file!
          break;
      printf("%c",a[i]);
  }
  fclose(wse);
 return 0;
}

```
Please find the corrected code :

```
FILE *wse;
char a[1000];
int i=0;

wse=fopen("21e.txt","r");

while(fscanf(wse,"%c",&a[i]) == 1)
{
    printf("%c",a[i]);
    i++;
}

```

Firstly, I corrected the code by removing your semicolon after the for loop. And secondly, replaced for with while loop so that it reads till end of file. It is because if the loop crosses EOF(End Of File), it might crash.