@Adak so i fixed up my code a little, and now it prints the table just like it is in the .txt file, but I STILL get the stupid junk values at the end!!! WHY?!
Code:
#include <stdio.h>
int main()
{
int c, i, j, row, col, nl, cr;
row = col = nl = cr = 0;
FILE *fp = fopen("sales.txt", "r");
// Figure out how many rows and columns the text file has
while ((c = getc(fp)) != EOF)
{
if (c == '\n')
nl++;
if (c == '\r')
cr++;
col++;
if (c == '\n')
row++;
putchar(c);
}
col = (col - (nl + cr));
col = (int) (col/row);
printf("\nnumber of rows is %d\n", row);
// read letters into array
char array[row][col];
if ( fp )
{
for ( ;; )
{
c = getc(fp);
if ( c == EOF )
{
break;
}
if ( c != '\n' && c != '\r' )
{
array[i][j] = c;
if ( ++j >= col )
{
j = 0;
if ( ++i >= row )
{
break;
}
}
}
}
fclose(fp);
}
for ( i = 0; i < row; i++ )
{
for ( j = 0; j < col; j++ )
{
putchar(array[i][j]);
}
putchar('\n');
}
return 0;
}
and the sales.txt file contains this:
Code:
4
25 20 25 25
20 22 23 22
25 26 25 22
30 28 25 26
25 30 45 20
30 25 20 21
27 25 24 26
20 23 24 20
28 26 24 25
30 10 35 32
28 29 30 35
15 16 15 14
12 15 12 19
20 24 20 18
10 15 12 16
32 30 33 29