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

  • Home
  • SEARCH
  • 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 8885089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:13:27+00:00 2026-06-14T21:13:27+00:00

I have a character array of 256 characters or char myArray[256] only the first

  • 0

I have a character array of 256 characters or char myArray[256] only the first couple actually hold any information

myArray[0] = 'H';
myArray[1] = 'E';
myArray[2] = 'L';
myArray[3] = 'L';
myArray[4] = 'O';
myArray[5] = NULL;
myArray[6] = NULL;
// etc...

I won’t necessarily know exactly what is in the array, but I want to copy what is there, minus the null characters, to my buffer string string buffer

I thought the appropriate way to do this would be by doing the following:

buffer.append(myArray);

And the program would stop reading values once it encountered a nul character, but I’m not seeing that behavior. I’m seeing it copy the entirety of the array into my buffer, null characters and all. What would be the correct way to do this?

Edit: Some working code to make it easier

#include <string>
#include <iostream>

using namespace std;

int main()
{
    string buffer;
    char mychararray[256] = {NULL};

    mychararray[0] = 'H';
    mychararray[1] = 'e';
    mychararray[2] = 'l';
    mychararray[3] = 'l';
    mychararray[4] = 'o';

    buffer.append(mychararray);

    cout << buffer << endl;

    return 0;
}

Just realized I wasn’t initializing the null properly and my original way works. Sorry to waste yall’s time.

  • 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-14T21:13:28+00:00Added an answer on June 14, 2026 at 9:13 pm

    Try with

    buffer += myArray;
    

    should do it. append should also work if you null-terminate the array.

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

Sidebar

Related Questions

In my main file I have an array of character strings, char names[320][30], and
I have an array of 4 characters, for example: char char_array[10]; char_arr[0] = 'a';
I have a character pointer , char *buf; I have a array of integers
I have a character array as shown below : char[] pwdCharArray = abcdefghijklmnopqrstuvwxyzABCDEFG +
I have a Character array (not char array) and I want to convert it
Is a string actually a character array (is-a), or does it have a character
I have a pointer to a character array: space=(char**)calloc(100000,sizeof(char*)); for(i=0;i<100000;i++){ space[i]=(char*)calloc(1,sizeof(char)); } such that
I have the following character array: char mychars[SIZE]; I would like to copy one
I have a character array defined in a header //header.h const char* temp[] =
I have a character array and I'm trying to figure out if it matches

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.