Take a look at the source code for killall5 (which pidof actually runs; note line 1021 which passes control to the function main_pidof).
sysvinit/killall5.c at master * limingth/sysvinit * GitHub
Or maybe you're thinking of something more along these lines:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
if (argc != 2)
{
fprintf(stderr, "Usage: mypidof PROGNAME\n");
exit(EXIT_FAILURE);
}
char line[1024] = "pidof ";
strncat(line, argv[1], sizeof line - 7);
FILE *fin = popen(line, "r");
while (fgets(line, sizeof line, fin))
printf("%s", line);
pclose(fin);
return 0;
}