You should definitely make temp an unsigned char or use a cast as you use it to index into the array fre. char can be, and often is, signed by default so any negative values would access outside the boundaries of the array. By the way, you should make fre one item larger to accommodate for all 8-bit values, including 255.
Note that you do not count the first argument, so fancyMostFrequentChar('a', 'b', 'a', '\0') would return 'b' instead of 'a'.
Note also (as commented by M.M) that the first argument should be defined as int for va_start to have defined behavior:
7.16.1.4 The va_start macro
Synopsis
#include <stdarg.h>
void va_start(va_list ap, parmN);
Description
The va_start macro shall be invoked before any access to the unnamed arguments.
The va_start macro initializes ap for subsequent use by the va_arg and va_end macros. [...]
The parameter parmN is the identifier of the rightmost parameter in the variable parameter list in the function definition (the one just before the , ...). If the parameter parmN is declared with the register storage class, with a function or array type, or with a type that is not compatible with the type that results after application of the default argument promotions, the behavior is undefined.
You mention you are not supposed to change the prototype... Unfortunately the prototype as posted char fancyMostFrequentChar(char c, ...) cannot be used to access the arguments past the first one.
Here is a corrected version:
char fancyMostFrequentChar(int c, ...) {
int fre[256] = { 0 };
char temp, res = (char)c;
if (res != '\0') {
va_list argp;
va_start(argp, c);
++fre[(unsigned char)res];
//This for loop will run through the arguments
//and record their frequencies into fre[] array
while ((temp = va_arg(argp, char)) != '\0') {
if (++fre[(unsigned char)temp] > fre[(unsigned char)res]) {
res = temp;
}
va_end(argp);
}
return res;
}
charcan (implementation defined) be signed, so the index can be negative.'c','\0'), an uninitialized variablejis returned. andva_arg(argp, char)-->va_arg(argp, int)int fre[255]==>int fre[256]