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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:31:21+00:00 2026-05-23T15:31:21+00:00

I need to send a pointer to a character array to one of my

  • 0

I need to send a pointer to a character array to one of my functions. To produce this char*, I use this function in one of my c files such that is called like this

charPtr = myProj.strAll ( 8 );

where strAll is:

char * strAll ( int size ) {
    return malloc( sizeof( char ) * size );
}

I then pass charPtr into a function like this:

myProj.Populate ( char* dataIn, char* dataOut, maxLen );

Populate copies dataIn into dataOut, using maxLen as the size restriction. It uses memcpy to copy it over through something like this:

memcpy ( dataOut, dataIn, maxLen);

Usage:

myProj.Populate ( "ABCD1234", charPtr, 8 ); //maxLen is the # of bytes I've allocated for charPtr.

However, when I tell python to print charPtr out, it will only print ABC.

Expected:

>>charPtr
'ABCD1234'
>>print charPTr
ABCD1234

Actual:

>>charPtr
'ABC'
>>print charPTr
ABC

Does anyone know what is happening?

  • 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-23T15:31:21+00:00Added an answer on May 23, 2026 at 3:31 pm

    ABCD1234 has 8 characters. But you should also provide an extra byte for the termination character \0. Every C string should be terminated by \0.

    myProj.Populate ( "ABCD1234", charPtr, 8 );
    

    charPtr should be pointing to a location which can accommodate 9 characters out of which the last is to place the termination character.

    And I amn’t sure why are you just allocating 5 locations where you are trying to copy a string of 8 characters long.

    charPtr = myProj.strAll ( 5 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pointer in an objective-C class that I need to send messages
We need to send uploaded files from our CMS website to any antivirus product
I need to send different IEnumerables to an Printer object. This printer object will
Just started working on a c project. Need help with passing function pointers/macro functions/etc.
I have a Functor which I need to send to a function which receives
I have a char * buffer that is filled by an API function. I
I need send certain attributes(say, human readable user name) from server to client after
I need to send hundreds of newsletters, but would like to check first if
I need to send and receive data over serial connections (RS-232 and RS-422). How
I need to send MMS thought a C# application. I have already found 2

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.