Hey everyone,
So i have this bit of code here, and it reads values from a text file named sales.txt
Code:
#include <stdio.h>
#define MAX_ROWS 25
#define MAX_COLS 20
int main()
{
FILE *fp = fopen("sales.txt", "r");
char array[25][20];
int i = 0;
int j = 0;
int row = 25;
int col = 20;
if ( fp )
{
for ( ;; )
{
int 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;
}
the results I get when i run the program are these:
Code:
425 20 25 2520 22 23
2225 26 25 2230 28
25 2625 30 45 2030 2
5 20 2127 25 24 2620
23 24 2028 26 24 25
30 10 35 3228 29 30
3515 16 15 1412 15 1
2 1920 24 20 1810 15
12 1632 30 33 29aa-
GCCLIBCYGMING-EH-TDM
1-SJLJ-GTHR-MINGW32
h$7 ⌐1@ ╚■( å→@ t☺s
╕■( ╒qÖw♥ ☻ ☻☻
ε<ò p☺ q☻ ╪↨7
h$aaaaaaaaaaAAaA
x♫7 x♫7 ê■( Ç⌠Au 7
ë⌠Au x♫7 x♫7
¿■( Ç⌠Au 7 ë⌠Au
▓╒ñ▲♦ |♫7 x♫7 ╩·ôw
"►ûw $ ÿ■( ♦
╝Væ≈¿■( ÷Au
╚←@ ╝■( BñAu¿☻Ku
ⁿ■( ╥⌠A Ä◄Bub◄Bu
µ╒ñ▲ ╚←@ P↑@
╨■( ( ─ ( ╒îCur:╬k
Process returned 0 (0x0) execution time : 0.090 s
Press any key to continue.
why on earth am I getting weird symbols and junk values?!?!
the sales.txt file has these contents:
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
the 4 at the very top of the sales.txt file represents the number of weeks. this number (4) is then followed by the weekly sales for the salespeople listed in the sales.txt file.
I also have another file that I try to read, it's called names.txt and its contents are:
Code:
16
Kelly, Victor
Lam, Gary
Nagasake, David
Nguyen, Jeff
Nguyen, Michael
Sinn, Scott
Smith, Jacob
Son, Thai
Tavares, Maribel
Tran, Diane
Tsukamoto, Andrew
Wang, Mary
Young, Daniel
Wells, Steve
Wong, Justin
Johnson, Mary
I get junk values for this too when i run it instead of sales.txt....
Btw, for the names.txt, the number 16 at the top means there are 16 salespeople. they're listed one name per line (last name, first name).
Please help!!
Thank you