Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef int (*PREDICATE)(const void*);
  6.  
  7. // ------------------------------------------------------
  8.  
  9. int filter(void* output, const void* input, int length, int item_size, PREDICATE pred)
  10. {
  11.     // FILL ME IN!
  12. }
  13.  
  14. int less_than_50(const void* p)
  15. {
  16.     // FILL ME IN!
  17. }
  18.  
  19. // ------------------------------------------------------
  20. // you shouldn't have to change the stuff below here.
  21. // you can for testing, but please put it back the way it was before you submit.
  22.  
  23. #define NUM_VALUES 10
  24.  
  25. float float_values[NUM_VALUES] =
  26. {
  27.     31.94, 61.50, 36.10,  1.00,  6.35,
  28.     20.76, 69.30, 19.60, 79.74, 51.29,
  29. };
  30.  
  31. int main()
  32. {
  33.     float filtered[NUM_VALUES];
  34.     int filtered_len = filter(filtered, float_values, NUM_VALUES, sizeof(float), &less_than_50);
  35.  
  36.     printf("there are %d numbers less than 50:\n", filtered_len);
  37.  
  38.     for(int i = 0; i < filtered_len; i++)
  39.         printf("\t%.2f\n", filtered[i]);
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement