Hi There,
I'm having problems adding up column totals using arrays. I've got it to add up the row totals and display at the end of the row.
Here is my code so far
Code:
#include <stdio.h>
#include <string.h>
const int maxrows=10;
const int maxcols=12;
//const int maxchar=25;
int num[maxrows][maxcols];
int total,arraytotal;
static char name[maxrows][maxcols];
int dummyage;
//static char name[maxrows][maxchar];
static char dummy[maxcols];
FILE *fp; /*identify the file by pointer reference */
main()
{
int i=0;
if((fp = fopen("sales10.txt","r"))==NULL) /*open data file for reading */
printf("error opening file\n");
else
{
do
{
printf("\n\t\t");
fscanf(fp,"%s",&dummy);
strcpy(name[i],dummy);
printf("\n%8s",name[i]);
total =0;
for(int j=0;j<maxcols;j++)
{
fscanf(fp,"%d",&num[i][j]);
printf("%5d",num[i][j]);
total=total+num[i][j]; /*calculate row sums*/
}
printf("%8d",total); /*display row sums*/
i++;
}while((strcmp(dummy,"ZZZZZ")!=0)and(i<maxrows));
printf("\n\n%5d",num[6][11]);
fclose(fp);
getchar();
}
}
What i need it to do is, add up the columns and display it at the bottom of each column similar to how the row totals display