Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8937553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:26:10+00:00 2026-06-15T10:26:10+00:00

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]); }

  • 0
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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:26:11+00:00Added an answer on June 15, 2026 at 10:26 am

    I assume that php_sprintf refers to the internal PHP function used when you write extensions for PHP. Then it has the same parameters as the C function sprintf.

    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:

    void PrintMACaddress(unsigned char MACData[]){
        php_printf("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n", 
            MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
    }
    

    If you want to return the value instead of printing it to the output, the there are few points to note:

    • When you work with strings in C++, you can represent it as either char * or std::string
    • Using std::string is the C++ way to go.
    • Using char * is more C-ish style. You have to manage the memory array by yourself (allocate on the stack or by using new [] and delete [])

    If I rewrite the method using std::string:

    std::string PrintMACaddress(unsigned char MACData[]){
        char tmp_[32]; // The output string should be always 32 bytes long
        php_sprintf(tmp_,"MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n", 
            MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
        return std::string(tmp_);
    }
    

    If you want to (or have to) use char *:

    char *PrintMACaddress(char *MACString, unsigned char MACData[]){
        php_sprintf(MACString,"MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n", 
            MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
        return MACString;
    }
    

    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:

    char macString[44];
    PrintMACaddress(macString, MACData);
    /* Use the string stored in macString */   
    

    or

    char* macString = new char[44];
    PrintMACaddress(macString, MACData);
    /* Use the string stored in macString */   
    delete [] macString;
    

    EDIT: Updated second part of the answer with php_sprintf

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found code: static void PrintMACaddress(unsigned char MACData[]) { printf(MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n, MACData[0], MACData[1],
void test() { unsigned char c; c = (~0)>>1 ; printf(c is %u\n,c); }
void* myfunction() { char *p; *p = 0; return (void*) &p; } I know
void say(char msg[]) { // using pointer to print out the first char of
void return_input (void) { char array[30]; gets (array); printf(%s\n, array); } After compiling it
void foo() { //some code MyClass m(); //some more code } Does the C++
void max_min(sqlite3 *db) { //call back********* int i, ncols; sqlite3_stmt *stmt; char *sql; const
void expand_combinations(const char *remaining_string, string const & s, int rema in_depth) { if(remain_depth==0) {
void reverse_string(char* string, int str_size) { char tmp; int i = 0; int j
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { xmlParseChunk(context, (const char *)[data bytes], [data length], 0);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.