Question: Here is my code. It currently reads from a text file, one line at a time. I have used strcpy to store each line into the array "lines". My question is, how do I print out an element of this arrray? Currently this code compiles and runs, but there is no output.

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

int main()
{
    FILE *ptr_file;
    char buf[1000];
    char lines[10][500];

    //num of strings, length of strings
    char *pointertoarray = lines[0];

    ptr_file =fopen("d1.txt","r");

    fgets(buf,1000, ptr_file)!=NULL;
    strcpy(buf, lines[0]);

    fgets(buf,1000, ptr_file)!=NULL;
    strcpy(buf, lines[1]);

    fclose(ptr_file);

    printf("%s", pointertoarray);

    return 0;
}   

```

Answer: 
This:

```
strcpy(buf, lines[0]);

```

Should be:

```
strcpy(lines[0], buf);

```

And to print it you could do:

```
printf("%s\n", lines[0]);
printf("%s\n", lines[1]);

```

Also, you're reading in a 1000 char string and copying it to a 500 char buffer... this might not be so good. Adjust the buffer so the sizes match or use strncpy to limit the amount of chars you copy so you don't overflow.

In any case, you might want to use a loop to read in lines and not hard code it. You could use fgets to read lines and dynamically allocate memory with malloc for each new line. It's a bit more work, but a lot better in the end as it will allow you to read files with an unknown number of lines, instead of having to decide before how many lines to read.
You would want to use a loop to print it out. The following will print out all of the contents of the array. In C, you can use a *for* or a *while* loop.

You may want to define the size of the array outside of the main:

```
#DEFINE SIZE1 1000;
#DEFINE SIZE2 10;

```

You could say:

```
int count = 0;
int count2 = 0;
for(count1 = 0; count1 < SIZE1; count1++)
{
     for(count2 = 0; count2 < SIZE2; count2++)
    {
          printf("%c", lines[count2][count1]);
    }
       printf("\n");
}

```