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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:11:35+00:00 2026-06-04T23:11:35+00:00

I have a string I composed using memcpy() that (when expanded) looks like this:

  • 0

I have a string I composed using memcpy() that (when expanded) looks like this:

char* str = "AAAA\x00\x00\x00...\x11\x11\x11\x11\x00\x00...";

I would like to print every character in the string, and if the character is null, print out "(null)" as a substitute for ‘\0’.

If I use a function like puts() or printf() it will just end at the first null and print out

AAAA

So how can I get it to print out the actual word “(null)” without it interpreting it as the end of the string?

  • 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-04T23:11:38+00:00Added an answer on June 4, 2026 at 11:11 pm

    You have to do that mapping yourself. If you want to, that is. In C, strings are null-terminated. So, if you use a formatted output function such as printf or puts and ask it to print a string (via the format specifier %s) it’d stop printing str as soon as it hits the first null. There is no null word in C. If you know exactly how many characters you have in str you might as well loop over them and print the characters out individually, substituting the 0 by your chosen mnemonic.

    The draft says 7.21.6.1/8:

    p The argument shall be a pointer to void. The value of the pointer is
    converted to a sequence of printing characters, in an
    implementation-defined manner.

    However, the following:

    $ cat null.c
    #include <stdio.h>
    int main() {
     printf("%p\n", (void *)0);
    }
    

    produces:

    00000000
    

    on both gcc 4.6 and clang 3.2.

    However, on digging deeper:

    $ cat null.c
    #include <stdio.h>
    int main() {
     printf("%s\n", (void *)0);
    }
    

    does indeed produce the desired output:

    (null)
    

    on both gcc and clang.

    Note that the standard does not mandate this:

    s If no l length modifier is present, the argument shall be a pointer
    to the initial element of an array of character type.280) Characters
    from the array are written up to (but not including) the terminating
    null character. If the precision is specified, no more than that many
    bytes are written. If the precision is not specified or is greater
    than the size of the array, the array shall contain a null character.

    Relying on this behavior may lead to surprises!

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

Sidebar

Related Questions

I have string like \LESSING\root\cimv2:Win32_UserAccount.Domain=LESSING,Name=Admin How to convert it to LESSING\Admin using Framework?
I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I have: String uri = @drawable/myresource.png; How can I load that in ImageView? this.setImageDrawable?
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
let's say that I have structure like this : As most you may see
i have string stored in python variables, and i am outputting a html that
I have string: text and something and something like f213 @@ -1,9 +1,11 @@
I have string like {param1=foo}{param2=bar}hello world! I need to extract array of tuples (paramName,
I have a long string composed of a number of different words. I want

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.