submitted for Coursera quiz. Read int's from a file, and calculate their average
#include <stdio.h>
int main(){
FILE *filePointer; // this is the pointer to the file
int buffer[1000]; // file content
int safety = 10000;
int count = 0;
filePointer = fopen("file.tsv", "r"); // open the file with file pointer to the file
while(fscan(filePointer, "%d\t", &buffer[count]) && --safety){
count++;
} // read the file the file pointer file
fclose(filePointer); // close the file pointer to the file
int total = 0; // total the weight
for(int xint = 0;xint<count;xint++)total+=buffer[xint]; // it make the total the total to make the average
int average=total/count;
printf("average:%d",count);
}
No comments:
Post a Comment