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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:26:27+00:00 2026-05-26T00:26:27+00:00

I want to create a global 22 character (+ NULL) string in C. I

  • 0

I want to create a global 22 character (+ NULL) string in C. I am initialising it like this:

#define SVN_REVISION     "1143"
#define SERIAL_NUMBER    "PST3201109270001"
char general_info[23] = SVN_REVISION SERIAL_NUMBER SAMPLING_FREQUENCY;

So far, this works fine. general_info is initialised with the concatenation of the two strings. Now, for the last two characters, I want them to be a 16-bit integer. But I can’t simply do this:

#define SVN_REVISION          "1143"
#define SERIAL_NUMBER         "PST3201109270001"
#define SAMPLING_FREQUENCY    (UINT16)500
char general_info[23] = SVN_REVISION SERIAL_NUMBER SAMPLING_FREQUENCY SAMPLING_FREQUENCY;

What can I do?

  • 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-05-26T00:26:27+00:00Added an answer on May 26, 2026 at 12:26 am

    If you mean you want to embed 16-bit integer 500 as binary data in the end of the string, you can use raw hex bytes:

    /* Little-endian unsigned 16-bit integer with the value 500 */
    #define SAMPLING_FREQUENCY    "\xf4\x01"
    

    Beware, though, endianness is architecture dependent, so you might want to add an extra macro to correctly order the bytes depending on the architecture:

    #ifdef ... /* little endian */
    #define BYTES2(a,b) b a
    #else ... /* big endian */
    #define BYTES2(a,b) a b
    #endif
    #define SAMPLING_FREQUENCY    BYTES16("x01", "\xf4")
    

    EDIT: If you want to have a human-readable number, you can’t have it at compile-time (at least not in C), but you can initialize it at runtime:

    #define SVN_REVISION     "1143"
    #define SERIAL_NUMBER    "PST3201109270001"
    #pragma pack(push, 1)
    union {
        struct {
            char svn_rev_serial[20];
            uint16_t freq;
            char nul;
        };
        char general_info[23];
    } u = {{
        SVN_REVISION SERIAL_NUMBER,
        500,
        '\0'
    }};
    #pragma pack(pop)
    

    This uses more non-standard (but well-supported) constructs, like #pragma pack and writing to one union member and reading from another.

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

Sidebar

Related Questions

I want to create my Rails application with MySQL, because I like it so
I want to create a number of masked edit extenders from codebehind. Something like:
I want to create dynamic content based on this. I know it's somewhere, as
Application running in django, apache, python and mysql: I want to create global variable
I want to create a global shortcut for my app. I've used the 'cool
I want to create a global option that when a REST call contains &format=json
I want to know the global mechanism for exception handling. Like I do have
Possible Duplicate: Global int variable objective c I would like to create a global
I want to create a global function to use throughout my application. Let say
I want to create a global connection class from Sql server database to vb.net

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.