Snprintf () Excuse me

Source: Internet
Author: User
Snprintf () ask unsigned & nbsp; char & nbsp; * mac & nbsp; = & nbsp; (unsigned & nbsp; char & nbsp; *) & amp; macAddr; & nbsp; snprintf (strMac, & nbsp; 33, & nbsp; "% 02X % 02X snprintf () ask for advice
Unsigned char * mac = (unsigned char *) & macAddr;
Snprintf (strMac, 33, "% 02X % 02X % 02X % 02X % 02X % 02X % 02X % 02X", mac [0], mac [1], mac [2], mac [3], mac [4], mac [5], mac [6], mac [7]);
This is the processing method in C ++.


Now I know how to use php to get the mac from strMac.
C ++ php
------ Solution --------------------

Snprintf usage

Header File

Stdio. h

Category

Memory and String Manipulation Routines

Prototype

Int snprintf (char * buffer, size_t nsize, const char * fmt ,...);

Int snwprintf (wchar_t * buffer, size_t nsize, const wchar_t * fmt ,...);

Description

Sends formatted output to a buffer of a maximum length specified by nsize.

If the number of bytes to output is:

<Nsize, then all of the characters have been written, including the terminating limit 0? Character.
= Nsize, then nsize characters are written, with no terminating limit 0? Character.

> Nsize, then only nsize characters are written, with no terminating limit 0? Character.
If nsize is 0, then the string will not be written to (and may be NULL ).

Return Value

Number of bytes output, or, if nsize is 0, the number of bytes needed, not including the terminating limit 0? Character.

It is not easy for you to reverse the car. if you want to reverse the car, you should not say that it will be intercepted if the length is exceeded.
$ A = "123 ";
$ B = "4567 ";
$ C = $ a. $ B;
Just give you a $ c, you cannot determine the content of $ a at a time, even if you know the rules

------ Solution --------------------
1. the MAC address is 6 bytes, which can be expressed by 12 hexadecimal numbers.
2. Why do you have 16 hexadecimal numbers?
3. your strMac string is already represented by the MAC address. I don't know what else you want to handle it.
Related Keywords:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.