• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

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
0
cooling9999
Asked:
cooling9999
1 Solution
 
rajeev_devinCommented:
>>   fscan(fileName, "%f", &a[i][j]);  //#s in this one are floating.// then using the same to print.
It should be
fscanf(fileName, "%f", &a[i][j]);  //#s in this one are floating.// then using the same to print.

0
 
cooling9999Author Commented:
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?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now