You have omitted that information, but
digits
(initially) appears to be a 0-terminated array of "acceptable" characters.
You are abusing the symbol
digits
for iterating over that set of characters, thereby losing the reference to the start of this array. What you should do instead is introduce a helper variable for that particular purpose (i. e. iterating), e. g.:
for (int i = 0; i < q; ++i) {
char* pdigits = digits;
while (*pdigits) {
if (budget[i] == *pdigits++) {
}
}
}