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 8145675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:44:44+00:00 2026-06-06T13:44:44+00:00

What I need to do is the following. const char *arrayHex[4]; for( int i

  • 0

What I need to do is the following.

const char *arrayHex[4];
for( int i = 0; i < 5; i++ )
{    
cin << uHex;
arrayHex[i] = uHex;
}

But I need the members of arrayHex to be hex escaped with \x. How might I go about doing that?

This was really vaguely worded, edit to fix(hopefully)

If the input is 41, I want the result when printed to be “A”, as if the value was “\x41”

  • 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-06T13:44:45+00:00Added an answer on June 6, 2026 at 1:44 pm
    #include <iostream>
    #include <string>
    #include <cstdlib> // for strtol()
    #include <cstdio>  // for printf()
    #define countof(array) (sizeof(array)/sizeof(array[0]))
    
    int main()
    {
        std::string uHex;
        long arrayValues[4];
        for( int i = 0; i < countof(arrayValues); ++i )
        {
            std::cin >> uHex;
            char* end;
            arrayValues[i] = std::strtol(uHex.c_str(), &end, 16);
            // At this point, we expect end to be pointing at the '\0'
            // (the C-string nul terminator).  If it's not, then we have
            // invalid chars in our input, and arrayValues[i] is bogus.
            if (*end != '\0')
            {
               std::cout << "Invalid characters: \"" << uHex << "\" (please try again)\n";
               --i; // compensate for the ++i above to re-try this again
            }
        }
    
        for( int i = 0; i < countof(arrayValues); ++i )
        {
            std::cout << i << " --> " << arrayValues[i] << " --> "
                      << static_cast<char>(arrayValues[i]) << '\n';
    //      std::printf("%d --> %d --> %c\n", i, arrayValues[i], arrayValues[i]);
        }
    }
    

    Note that I’m printing the exact same output both ways: with cout or with printf(). Personally I like printf() not because that’s what I learned first, but because printf() formatted output is significantly more expressive (for MOST built-in types) with less verbosity than cout, even though cout is more flexible because you can create cout output functions for user-defined types. But if your compiler doesn’t do printf()/scanf() format-parameter type checking (GCC does, if you enable it), then you can easily create some interesting & confusing output with mismatched types, and create nice non-deterministic SEGV generators quite easily by specifying less args than your format string indicates.

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

Sidebar

Related Questions

The following C function: int sprintf ( char * str, const char * format,
So...I have the following code: int main(void) { const char *s=hello, world; cout<<&s[7]<<endl; return
I have following array, that I need to operate by hand on bitmaps. const
Consider the following simple map: class MyCoolMap : public unordered_map<const char *, const char
I have a const char* str with a very long string. I need to
I have the following old c code. const char *c[3]; c[0] = ABC; c[1]
I have code that works but only once. I need an input char a
I need the following authentication script finished. I am weak at php/pdo so I
I need the following logic. If array contains value , return it else return
For a part of a program i need the following 2 methods. The first

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.