Creating an array of strings from a text file I'm try to create array of strings from a text file. I need a review from experienced programmers about my program. (MinGW gcc, Win7)

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;

main()
{
FILE *file; 
char *fname = "lines.txt";
file = fopen(fname, "r");

if(file == NULL)
    printf("Can't read %s", fname);

char cbuff;

int nlines = 0; //counter of new lines
int chr = 0; //counter of chars (except new line char)

int maxlen = 0;
while( (cbuff = fgetc(file) - 0) != EOF )
{
    if(cbuff == '\n')
    {
        if (chr &gt; maxlen)
        {
            maxlen = chr + 1;
        }

        chr = 0;
        nlines++;
    }

    else
    {
    chr++;
    }
}

printf( "lines: %d\nmax string len: %d\n\n", nlines, maxlen );
rewind(file);

char *list[nlines];

int buffsize = maxlen * sizeof(char);
char buff[buffsize];

int i = 0;
while(fgets(buff, buffsize, file))
{

    list[i] = malloc(strlen(buff) * sizeof(char));
    strcpy(list[i], buff);
    i++;
}

fclose(file);

int c = 0;
for(c; c &lt; nlines; c++)
{
    printf( "%s", list[c] );
}
}//main


I'm trying to control size of array and items in array. Maybe I have errors somewhere, do not judge strictly.
If you are truly coding in C then all variables should be declared at the start of the function. This has traditionally been how the C language worked and what C coders expect.

C has also traditionally not allowed for runtime declarations of array sizes. You should malloc the list variable.

If you initialize a loop variable then just omit it in the for loop definition. In other words don't do this:

for(c; c &lt; foo; c++)


do this:

for( ; c &lt; foo; c++)


A char is already a byte, no need to multiple strlen by sizeof(char).

Personally I would move most of the logic into proper functions and out of main. It is just a good habit to get into.