Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. enum type(INT,DOUBLE,LONG);
  2.  
  3. #define CheckIfExist(arr, num, type, count, len)\
  4. {\
  5. int i;\
  6. type * ptr = (type *)arr;\
  7. type * nPtr = (type *) num;\
  8. for(i=0; i<len; i++, ptr++)\
  9. {\
  10. if(*ptr == *nPtr)\
  11. {\
  12. count = i+1;\
  13. }\
  14. }\
  15. }
  16.  
  17. double BodekImKayam(void* arr,void* num, int type, int len)
  18. {
  19. double count =0;
  20. switch (type) {
  21. case INT: {
  22. CheckIfExist(arr, num, int, count, len);
  23. return count;}
  24. case LONG: {
  25. CheckIfExist(arr, num, long, count, len);
  26. return count;}
  27. }
  28. }
  29.  
  30. int main ()
  31. {
  32. int arr[] = {1};
  33. int len = sizeof(arr)/sizeof(arr[0]);
  34. int num = 77;
  35. if (BodekImKayam(arr,&num,INT,len) == 0)
  36. printf("num not found");
  37. return 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement