Skip to content

Instantly share code, notes, and snippets.

@SzymonFortuna
Created March 29, 2014 12:19
Show Gist options
  • Save SzymonFortuna/9853505 to your computer and use it in GitHub Desktop.
Save SzymonFortuna/9853505 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;
class Dane{
FILE *fp;
int colnum;
int rownum;
public:
Dane(const char* filename){
fp = fopen(filename,"r");
if(!fp){
printf("error");
}
}
void average(){
float a=0,b=0,c=0,d=0;
float tempa,tempb,tempc,tempd;
fscanf(fp,"%d",&colnum);
rewind(fp);
while(fgetc(fp) != EOF){
fseek(fp,-1,SEEK_CUR);
if (fgetc(fp)=='\n')
{rownum++;}
if(rownum>1){
fscanf(fp,"%f,%f,%f,%f",&tempa,&tempb,&tempc,&tempd);
a+=tempa;
b+=tempb;
c+=tempc;
d+=tempc;
}
}
printf("Średnia: %f %f %f %f\n",a/(rownum-2),b/(rownum-2),c/(rownum-2),d/(rownum-2));
}
};
int main(){
string filename = "Dane.csv";
Dane d = Dane(filename.c_str());
d.average();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment