We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


reading numbers from files into matrix then printing

cooling9999 asked
Medium Priority
Last Modified: 2012-05-05
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!
Watch Question

>>   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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


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?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.