hi, i am a new member here and first semester as a student using programming for my major (Geomatics Engineering). any feedback would be immensely appreciated. here it goes:
(also, pardon my probable terrible formatting, first post).
i am to write a program that reads a file that reads 3 arrays (essentially a 3x3 matrix) and i will end up printing them into a new file along with computing the averages of the values (column 1 avg,...)
however i am stuck far from that.
Code:/* * Programmer: Jeff Clay * Class: GME 61 * Date: 8-7-12 * Program: READING IN ARRAYS * * Purpose: READ IN ARRAYS, COMPUTE AVERAGE * */ #include <stdio.h> #include <stdlib.h> #define maxRow 2 #define maxCol 3 #define _CRT_SECURE_NO_WARNINGS void printMatrix(double array[maxRow][maxCol], int row, int column); void add_matrices(double xArray[maxRow][maxCol], double yArray[maxRow][maxCol], double zArray[maxRow][maxCol], int row, int column); main() { double xArray[1][3], yArray[1][3], zArray[1][3]; char fileName[256]; int i,j; FILE *fileIn, *fileOut; i=0; j=0; printf("Enter input file path:\n"); gets(fileName); fileIn=fopen(fileName, "r"); if (fileName==NULL) { printf("Filepath DNE"); exit(-1); } /*printf("Enter output file path:\n"); gets(fileName); fileOut=fopen(fileName, "w"); if (fileName==NULL) { printf("Filepath DNE"); exit(-1); }*/ while(fscanf_s(fileIn,"%lf", &xArray[3][1])!=EOF) /*add_matrices(xArray,yArray,zArray,3,1);*/ { printMatrix(xArray,3,1); /*printf("+ \n");*/ } /*double a[2][3]={{1.0, 2.0, 3.5},{4.0, 5.0, 6.0}}; double b[2][3]={{-6.0, -5.0, -4.0},{ -3.0, -2.1, -1.5}}; double c[2][3]; add_matrices(a,b,c,3,2); { printMatrix(a,3,2); printf("+ \n"); printMatrix(b,3,2); printf("= \n"); printMatrix(c,3,2); }*/ } void printMatrix(double array[maxRow][maxCol], int row, int column) { int i, j; for (i=0; i<column; i++) { for (j=0; j<row; j++) printf("%.2lf\t", array[i][j]); printf("\n"); } }
i'll be kind of honest, i am pretty lost on what i am doing and what to do. i understand the concept of an array, however the coding is not friendly to me.
thank you



LinkBack URL
About LinkBacks



