Advertisement
yasenst

zad 2

Jun 28th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. int kp(FILE* f)
  2. {
  3.     int sum = 0;
  4.     int num;
  5.    
  6.     while(fscanf(f,"%d", &num) != EOF)
  7.     {
  8.         if(num  < 0)
  9.             sum += num;
  10.     }
  11.     fclose(f);
  12.     return sum;
  13. }
  14.  
  15. int ab(char c, FILE* f)
  16. {
  17.     int count = 0;
  18.     char x;
  19.    
  20.     while(fscanf(f, "%c", &x) != EOF)
  21.     {
  22.         if(c == x)
  23.             count++;
  24.     }
  25.    
  26.     fclose(f);
  27.     return count;
  28. }
  29.  
  30. int main()
  31. {
  32.    FILE *f;
  33.    char x;
  34.    int result1, result2;
  35.    
  36.    scanf("%c", &x);
  37.    
  38.    fp = fopen("D:\\Tst1.txt", "r");
  39.    
  40.    result1 = kp(f);
  41.    
  42.    printf("Otricatelni: %d\n", result1);
  43.    
  44.    fp = fopen("D:\\Tst1.txt", "r");
  45.    
  46.    result2 = ab(x, f);
  47.    
  48.    printf("Suma: %d\n", result2);
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement