Advertisement
Kosty_Fomin

Untitled

Nov 28th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <sys/stat.h>
  6.  
  7. struct answers_1{
  8.     long long sum;
  9.     long long umn;
  10. };
  11.  
  12. struct answers_1  get_file_name(char *path);
  13.  
  14.  
  15. int main (void)
  16. {
  17.     struct answers_1  answers;
  18.     char* path = (char*) malloc( 100 );
  19.     printf("Input file name:\n");
  20.     scanf("%s",path);
  21.  
  22.     answers = get_file_name(path);
  23.    
  24.  
  25.     printf("Sum =  %lld Umn = %lld\n", answers.sum,answers.umn);
  26.  
  27. }
  28.  
  29.  
  30.  
  31.  
  32. struct answers_1  get_file_name(char *path){
  33.    
  34.     struct answers_1  answersf;
  35.     answersf.umn = 1;
  36.     answersf.sum = 0;
  37.    
  38.     FILE *in;
  39.     in = fopen(path, "r");
  40.    
  41.     if (in == NULL) {
  42.         exit(1);
  43.     }
  44.    
  45.     long long buf=0;
  46.    
  47.    
  48.     while ((fscanf(in, "%lld", &buf)!=EOF)) {
  49.         answersf.sum+=buf;
  50.         answersf.umn*=buf;
  51.     }
  52.     fclose(in);
  53.     return answersf;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement