Link to home
Start Free TrialLog in
Avatar of cooling9999
cooling9999

asked on

reading numbers from files into matrix then printing

Hi. okay, last week for my C course,i had to prompt a user for 20int (one at a time), which were scanned into an array.
so for that, i got:
SIZE = 20;
int a[20];
int i;

for(i=0; i<SIZE; i++){
  printf("prompt here");
  scanf("%d\n", a[i]0;
 }
for this week, we're supposed to write a program, using a read function and a print funtion to read a set of numbers from a file (entered by user) into a 5x5dim array and then print the contents of the matrix. i saw something online that seemed to be stating 2 scan statements (like above) simultaneously. I want to be able to scan in and print out as efficiently as possible. i'm thinking of nesting 2 "for" statements, something like:

for(i=0; i<SIZE; i++){
 for(j=0; j<SIZE; j++){
   fscan(fileName, "%f", &a[i][j]);  //#s in this one are floating.// then using the same to print.
please help!
thanks!!
-d
ASKER CERTIFIED SOLUTION
Avatar of rajeev_devin
rajeev_devin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cooling9999
cooling9999

ASKER

yea. typo. sorry.

is that all i need though?
do i need to scan in the file name or something to get the # in the file?