This is a very basic template for printing out a bar graph, in your program:
Code:
#include<stdio.h>
#define PI 3.14159
#define ROWS 10
#define COLS 30
void printGraph(void);
int main(){
int min, inches, c=0, i, flength;
double totalRev=0, totalGas=0, rev, gas;
char file[20];
FILE *fp;
printGraph();
/*
//printf("What file stores the car data?\n");
//scanf("%s", &file); printf("\n");
strcpy(file, "fuelsampl.txt");
flength = strlen(file);
if(file[flength-1]=='\n')
file[flength-1]='\0';
if((fp = fopen(file, "r"))==NULL) {
printf("\nError opening input file\n");
return 1;
}
fscanf(fp, "%d", &min);
fscanf(fp, "%d", &inches);
min = min/5;
double mpg[min];
while(c<min) {
for(i=1;i!=301;i++) {
fscanf(fp, "%lf%lf", &rev, &gas);
totalRev+=rev, totalGas+=gas;
}
mpg[c] = ( (PI * inches * 2 * totalRev) / 63360 ) / totalGas;
c++;
totalRev=0, totalGas=0;
}
//printGraph( mpg );
// c=0;
// while(c<=(min-1)){printf("%lf\t", mpg[c]); c++;}
//printf("%d", min);
fclose(fp);
*/
printf("\n\n\t\t\t press enter when ready");
(void) getchar();
return 0;
}
void printGraph(void) {
int i,r,c,n, width=5, twidth=35, theight=10;
//int y=100;
char dat[ROWS][COLS];
for(r=0,n=0;r<ROWS;r++) {
for(c=0;c<COLS;c++) {
dat[r][c]=' '; //just loads some char's
++n; //into the array, to show
if(n-127<r)
dat[r][c]='*'; //for a demo
}
}
//basic print out block
for(r=ROWS-1,n=45;r>-1;r--) {
printf(" %2d| ", n);
for(c=0;c<COLS;c++) {
if(c % width == 0 && c)
putchar(' ');
printf("%c",dat[r][c]);
}
putchar('\n');
n-=5;
}
//while(y!=0){y-=5; printf("%-4d", y);}
printf(" -----------------------------------\n");
printf(" 00-05 05-10 10-15 15-20 20-25 25-30\n");
}
All this does is print out a bar graph. You've gone on vacation?
Edit: demo output:
============
Code:
45|
40|
35|
30|
25|
20| ***** *****
15| ***** ***** ***** ***** ***** *****
10| ***** ***** ***** ***** ***** *****
5| ***** ***** ***** ***** ***** *****
0| ***** ***** ***** ***** ***** *****
-----------------------------------
00-05 05-10 10-15 15-20 20-25 25-30
press enter when ready