multiplying a matrix inputed from a file
Hey everyone,
I am creating a program that opens a file that contains a 4 x 6 matrix and then stores it in a two dimensional array. It then prompts the user to enter a number which the program multiplies each element of the array by and then stores it in a second two dimensional array to put into an output file. I am just having trouble with the multiplication, call of matrix, and and storing in the two dim array at this point. Any help with any aspect of this program is much appreciated. Thanks. By the way. I was having trouble with the indentation of my code when I displayed so I put the code also into an attachment because I am know that that is part of the protocol for posts.
Code:
#include<stdio.h>
#define ROWSIZE 4
#define COLUMNSIZE 6
int ma[ROWSIZE][COLUMNSIZE];
int mult(int x);
int main()
{
FILE *infile;
FILE *outfile;
int ma[ROWSIZE][COLUMNSIZE];
int i = 0;
int j = 0;
int multiplier;
infile = fopen("input_prelab3.txt", "r");
outfile = fopen("output_prelab3.txt", "w");
printf("Enter an integer to multiply to the loaded matrix: ");
scanf("%d", &multiplier);
if (infile)
{
for ( ;; )
{
int c = getc(infile);
if ( c == EOF )
break;
if ( c != '\n' && c != '\r' )
{
ma[i][j] = c;
if ( ++j >= COLUMNSIZE )
{
j = 0;
if ( ++i >= ROWSIZE )
break;
}
}
}
fclose(infile);
}
for (i = 0; i < ROWSIZE; i++)
{
for(j = 0; j < COLUMNSIZE; j++)
putint(ma[i][j]);
putint('\n');
}
return (int mult(int multiplier);
}
int mult(int x)
{
for (i = 0; i < 4; i++)
for (j = 0; j < 6; j++)
mb[i][j] = x * ma[i][j];
}
Thanks again.