I am working on a problem in C and I have a quick question about this. The problem is this: I am given some sorted array of integers, say a[i] = { 1, 2, 3, 3, 3 } . Now I have to run a program that looks for a given integer, returns the location of the first occurrence and the number of occurrences of this integer in the array.
So, if I were looking for 3 , then I would have the first occurrence in a[2] , and there are three occurrences of 3 . For the first part of searching for the first occurrence, I can simply use strcspn from the line header file. However, for the second part there is a built-in function that will count the number of instances of a certain integer?
I can actually do this with my bare hands just by incrementing the counter variable. However, my professor gave me a hint that the return type should be size_t, suggesting that some built-in functions could be used. Any help would be greatly appreciated.
Thank you, Alexander
source share