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: 
Step back a minute and learn the alternatives you have for input in C. You have *character oriented* input functions (`getchar()`, `fgetc()`, etc..) which will read a file one-character-at-a-time. You then have *line-oriented* input functions (e.g. `fgets` and `getline`) which will read lines of input at a time, and finally you have *block-oriented* input functions such as `fread` and `read` that you can use to read the entire file into a single block of memory. (there are some other tools for copying and memory access such as `sendfile` and `mmamp` that can also be utilized, but probably not intended here. The `scanf` family of functions, while they do have there uses, are not intended to read differing values over multiple lines.

Your basic approach should either be *character-oriented* input or *line-oriented* input to read a file into an array. The easier or the two would probably be *line-oriented* input where you would read an entire line and then *tokenize* the line into separate words with `strtok` (or by using a start and end pointer to walk down each line after it is read separating words).

Take a stab an your chosen approach and post back when you get stuck. We are happy to help.

A short example of using `fgets` to read each line following by `strtok` to separate each line into words could be something similar to the following. **note**: the program will read from the filename given on the command line (or from `stdin` by default if no name is given)

```
#include <stdio.h>
#include <string.h>

enum {MAXC = 1000};

int main (int argc, char **argv) {

    char buf[MAXC] = "";
    char *delims = " \t\n.,:;";  /* word separators for strtok */
    FILE *fp = argc > 1 ? fopen (argv[1], "r") : stdin;

    if (!fp) {  /* always validate file is open for reading */
        fprintf (stderr, "error: file open failed '%s'.\n", argv[1]);
        return 1;
    }

    while (fgets (buf, MAXC, stdin)) {  /* read each line into buf */
        char *p = buf;
        printf ("\n line:  %s\n tokens:\n", buf);
        /* tokenize buf into words with strtok */
        for (p = strtok (buf, delims); p; p = strtok (NULL, delims))
            printf ("   %s\n", p);
    }
    if (fp != stdin) fclose (fp);  /* close if not reading stdin */

    return 0;
}

```

**Example Input**

```
$ cat dat/captnjack.txt
This is a tale
Of Captain Jack Sparrow
A Pirate So Brave
On the Seven Seas.

```

**Example/Output**

```
$ ./bin/strtok_fgets_file <dat/captnjack.txt

 line:  This is a tale

 tokens:
   This
   is
   a
   tale

 line:  Of Captain Jack Sparrow

 tokens:
   Of
   Captain
   Jack
   Sparrow

 line:  A Pirate So Brave

 tokens:
   A
   Pirate
   So
   Brave

 line:  On the Seven Seas.

 tokens:
   On
   the
   Seven
   Seas

```
Just use `fgetc` and `putchar`, since you are reading character-by character

```
int c;
while ((c = fgetc(fp)) != EOF)
    putchar(c);

```

Also, check the return value of `fopen`. It returns a `NULL` on failure.