Using a "char" with VERY BIG capacity

Hi,

I am using a pipe with an external software in a c++ program.
The method to send a given command through the pipe takes as argument:
- a char* containing the command to send,
- a second char* where to copy the output coming from the command that has just been sent, and
- the size of this latter parameter.

under the form: SendCommand(line, line, sizeof(line));


For one of my commands, the output coming from the pipe (2nd parameter) features 5 or 6 pages of characters, that is why I'd like to know if someone would know how to store all of that in a variable of type char* (that I copy to an external .txt file afterward).

Thank you in advance,
Sky
PS:

For this command "report species", I have the following code so far:
1
2
3
4
char line[200];
sprintf_s(line, "report species");
SendCommand(line, line, sizeof(line));
std::cout << line << std::endl;
I would not use the same buffer for input/output unless the SendCommand function specifically says that's OK in the documentation. Otherwise, when SendCommand writes to the output buffer, it will wipe its input.

Something like this would be better:

1
2
char line[200];
SendCommand( "report species", line, sizeof(line) );


Note I pass "report species" directly, rather than sticking it 'line'.


Anyway, to store a larger number of characters, just make your buffer larger:

1
2
3
int size = 100000; /* or however big you need it */
char* line = new char[size];
SendCommand( "whatever", line, size );  // note that we can no longer use sizeof() here 
That seems to work, thank you very much.
Though, I notice that there is a size limit of 276447231.

(When I enter int size = 276447232 and display the size after have used my pointer the way I wanted, I notice its size has been decreased to 276447231...)

Do you know why?
Thank you

Sky
Topic archived. No new replies allowed.