We are writing a program that multiplies two matrices of size n x m and m x n together. The matrices are stored in a file. The user provides the filename in the command line prompt. The file is formatted like so:
/beginning/
matrix1
3 2
1 6
2 4
3 5
matrix2
2 3
2 8 9
8 2 1
/end/
matrix1 and matrix2 can be in any order. We are supposed to use string comparison to make sure that you are reading in the correct contents of the matrices. The first two numbers under the corresponding matrices are the dimensions.
I only need help with the string comparison. As of now I am only able to enter the file into an array. Here is what I have so far.
[code=c]
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#define MaxFilename 256
#define MaxColumnandRow s 1000
int main(int argc,char *argv[]){
char inputFile1[MaxFilename];
char outputFile1[MaxFilename];
char assignedValues[MaxColumnandRow s][MaxColumnandRow s];
int a,b,n,m,j,i,k;
int matrix1[20][20];
int matrix2[20][20];
int matrix3[20][20];
FILE *input1;
FILE *output1;
//User supplies input information
printf("Which file contains the information for the matrices?\n");
scanf("%s",&inp utFile1);
input1 = fopen(inputFile 1,"r");
if (input1 == 0)
{
printf("File Not Found\n");
exit(0);
}
//User supplies output information
printf("What output file will store the sorted items?\n");
scanf("%s",&out putFile1); //writes the matrix numbers to the file outputFile
output1=fopen(o utputFile1,"r+" );
//Read and Assign input info
for ( i=0; i<=10; i++)
{
for (j=0;j<=10;j++)
{
fscanf(input1," %c",&assignedVa lues[i][j]);
}
}
//printf("\n");
//printf("%c\n",a ssignedValues[0][6]);
//a=(int)assigned Values[0][6];
//printf("%d\n");
if (a==49)
{
for ( i=0; i<=10; i++)
{
for (j=0;j<=10;j++)
{
fcanf(input1,"% d",&matrix1[i][j];
printf("\nmatri x1\n");
}
}
row=matrix1[1][0];
column=matrix1[1][1];
}
else if (a==50)
{
for ( i=0; i<=20; i++)
{
for (j=0;j<=10;j++)
{
fcanf(input1,"% d",&matrix2[i][j];
printf("\nmatri x1\n");
}
}
row=matrix1[1][1];
column=matrix1[1][0];
printf("\nmatri x2\n");
}
else
{
printf("\nerror \n");
}
}
[/code]
I only need help with the string comparison part. Please let me know if any more info is needed.
Thanks.
/beginning/
matrix1
3 2
1 6
2 4
3 5
matrix2
2 3
2 8 9
8 2 1
/end/
matrix1 and matrix2 can be in any order. We are supposed to use string comparison to make sure that you are reading in the correct contents of the matrices. The first two numbers under the corresponding matrices are the dimensions.
I only need help with the string comparison. As of now I am only able to enter the file into an array. Here is what I have so far.
[code=c]
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#define MaxFilename 256
#define MaxColumnandRow s 1000
int main(int argc,char *argv[]){
char inputFile1[MaxFilename];
char outputFile1[MaxFilename];
char assignedValues[MaxColumnandRow s][MaxColumnandRow s];
int a,b,n,m,j,i,k;
int matrix1[20][20];
int matrix2[20][20];
int matrix3[20][20];
FILE *input1;
FILE *output1;
//User supplies input information
printf("Which file contains the information for the matrices?\n");
scanf("%s",&inp utFile1);
input1 = fopen(inputFile 1,"r");
if (input1 == 0)
{
printf("File Not Found\n");
exit(0);
}
//User supplies output information
printf("What output file will store the sorted items?\n");
scanf("%s",&out putFile1); //writes the matrix numbers to the file outputFile
output1=fopen(o utputFile1,"r+" );
//Read and Assign input info
for ( i=0; i<=10; i++)
{
for (j=0;j<=10;j++)
{
fscanf(input1," %c",&assignedVa lues[i][j]);
}
}
//printf("\n");
//printf("%c\n",a ssignedValues[0][6]);
//a=(int)assigned Values[0][6];
//printf("%d\n");
if (a==49)
{
for ( i=0; i<=10; i++)
{
for (j=0;j<=10;j++)
{
fcanf(input1,"% d",&matrix1[i][j];
printf("\nmatri x1\n");
}
}
row=matrix1[1][0];
column=matrix1[1][1];
}
else if (a==50)
{
for ( i=0; i<=20; i++)
{
for (j=0;j<=10;j++)
{
fcanf(input1,"% d",&matrix2[i][j];
printf("\nmatri x1\n");
}
}
row=matrix1[1][1];
column=matrix1[1][0];
printf("\nmatri x2\n");
}
else
{
printf("\nerror \n");
}
}
[/code]
I only need help with the string comparison part. Please let me know if any more info is needed.
Thanks.
Comment