Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <sys/stat.h>
- struct answers_1{
- long long sum;
- long long b;
- };
- struct answers_1 get_file_name(char *path);
- int main (void)
- {
- struct answers_1 answers;
- char* path = (char*) malloc( 100 );
- printf("Input file name:\n");
- scanf("%s",path);
- answers = get_file_name(path);
- printf("Sum = %lld ", answers.sum);
- }
- struct answers_1 get_file_name(char *path){
- struct answers_1 answersf;
- answersf.b = 0;
- answersf.sum = 0;
- FILE *in;
- in = fopen(path, "r");
- if (in == NULL) {
- exit(1);
- }
- long long buf=0;
- while ((fscanf(in, "%lld", &buf)!=EOF)) {
- answersf.sum+=buf;
- answersf.b++;
- }
- answersf.sum = answersf.sum/answersf.b;
- fclose(in);
- return answersf;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement