I don't think there is a similar function that let you specify the number of digits, but I don't know, I'm no expert on C string functions. It shouldn't be that hard to create your own. If you want to use strtoul you could copy the two digits to a null-terminated char array before using the function and then manually increment the str pointer by 2.
Note that UTF-8 uses 8-bit code units so when you're using putwchar, which outputs wide characters, your program is not really outputting UTF-8.
@Peter87 Yes its not outputting UTF-8 conversion really. If you know any code/function can you please tell me by which i can get UTF-8 conversion from Hex?
The title is misleading: based on the desired input/output, you're not working with UTF-8 in any capacity. You're simply reading a byte string where some bytes are encoded as three-byte sequences %xx where xx is hex.
Must it be in C? Here's a convenient way to set it up in C++:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
void show(const std::string& str)
{
std::string out;
parse(str.begin(), str.end(),
+('%' >> qi::int_parser<int,16,2,2>() | qi::char_), out);
std::cout << out << '\n';
}
int main()
{
show("%3d%22BoatsGreat%22");
show("%22%E7%8C%AB%F0%9F%90%B1%22"); // some UTf-8 for you
}
@cubbi Can you please show me how i can take input from user in your above code?
Because when i am doing it, giving me segmentation fault. its a large string of hex(hex string size greater than 4096) and while taking in cin it does not accept string greater than 4096.