void PrintMACaddress(unsigned char MACData[]){
php_sprintf("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
}
Output code is:
return PrintMACaddress(MACData);
When i click ‘build’, it show this error:
error C2664: ‘php_sprintf’ : cannot convert parameter 2 from ‘unsigned char’ to ‘const char *‘
Please help, I’m newbie in c++ and I already search around many days for this error.
I assume that
php_sprintfrefers to the internal PHP function used when you write extensions for PHP. Then it has the same parameters as theCfunctionsprintf.Are you trying to print the MAC address to the standard output or to a string?
If you want to print to the standard output (and subsequently to a console), then use
php_printf.So you code can look like:
If you want to return the value instead of printing it to the output, the there are few points to note:
char *orstd::stringstd::stringis the C++ way to go.char *is moreC-ish style. You have to manage the memory array by yourself (allocate on the stack or by usingnew []anddelete [])If I rewrite the method using
std::string:If you want to (or have to) use
char *:Here, the method gets one new parameter – pointer to allocated array of at least 32 bytes. It then returns the pointer to this array. You would use it like:
or
EDIT: Updated second part of the answer with php_sprintf