/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.
Expand|Select|Wrap|Line Numbers
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #define MaxFilename 256
- #define MaxColumnandRows 1000
- int main(int argc,char *argv[]){
- char inputFile1[MaxFilename];
- char outputFile1[MaxFilename];
- char assignedValues[MaxColumnandRows][MaxColumnandRows];
- 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",&inputFile1);
- input1 = fopen(inputFile1,"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",&outputFile1); //writes the matrix numbers to the file outputFile
- output1=fopen(outputFile1,"r+");
- //Read and Assign input info
- for ( i=0; i<=10; i++)
- {
- for (j=0;j<=10;j++)
- {
- fscanf(input1,"%c",&assignedValues[i][j]);
- }
- }
- //printf("\n");
- //printf("%c\n",assignedValues[0][6]);
- //a=(int)assignedValues[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("\nmatrix1\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("\nmatrix1\n");
- }
- }
- row=matrix1[1][1];
- column=matrix1[1][0];
- printf("\nmatrix2\n");
- }
- else
- {
- printf("\nerror\n");
- }
- }
Thanks.