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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:15:25+00:00 2026-05-30T13:15:25+00:00

When I run some code on my machine then it behaves as I expect

  • 0

When I run some code on my machine then it behaves as I expect it to.

When I run it on a colleagues it misbehaves. This is what happens.

I have a string with a value of:

croc_data_0001.idx

when I do a strncpy on the string providing 18 as the length my copied string has a value of:

croc_data_0001.idx♂

If I do the following

myCopiedString[18]='\0';
puts (myCopiedString);

Then the value of the copied string is:

croc_data_0001.idx

What could be causing this problem and why does it get resolved by setting the last char to \0?

  • 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-30T13:15:27+00:00Added an answer on May 30, 2026 at 1:15 pm

    According to http://www.cplusplus.com/reference/clibrary/cstring/strncpy/

    char * strncpy ( char * destination, const char * source, size_t num );
    Copy characters from string
    

    Copies the first num characters of source to destination. If the end
    of the source C string (which is signaled by a null-character) is
    found before num characters have been copied, destination is padded
    with zeros until a total of num characters have been written to it.
    No null-character is implicitly appended to the end of destination, so destination will only be null-terminated if the length
    of the C string in source is less than num.

    Thus, you need to manually terminate your destination with ‘\0’.

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

Sidebar

Related Questions

I need to run some code on a Linux machine with Python 2.3.4 pre-installed.
How can I automatically run some code when a WPF form is closed?
I like to run some code when a user closes my ms 2000 app.
I need to run some code that will fetch some configuration values from the
[Rails] I need to run some code only 40% of the times, how may
I would like to run some code onload of a form in WPF. Is
I receive a warning when I run some code through Visual Studio's Code Analysis
I mean, how does Java decide which protocols are available? I run some code
I'm trying to run some python code under Apache 2.2 / mod_python 3.2.8. Eventually
Where would set_include_path(../../); point to? I am trying to run some PHP code on

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.