Andreas Müller wrote:
hi @all,
I have a char* string[10] array and i want to fill it up in a while
loop:
while(i<3){
length = read(STDIN_FILENO, inputBuffer, sizeof(inputBuffer);
...
}
after this the array should look like this:
string[0]=the first entry
string[1]=the 2nd entry
string[2]=the third entry
string[i]=inputBuffer works for the 1st entry but not for the 2nd,
is this because of the null-terminated strings?
Can anybody help me?
thanks
Andreas
I think using C++ instead of C here would probably provide the most
help. One of the key advantages of using C++ streams and buffer classes
is that they take care of much of the memory management of I/O
operations.
The benefit is not just greater convenience. While it is true that the
C++ implementation is not only easier to write (because there is less
code that needs to be written), the real advantage lies in the greater
security and reliabilty provided by a standard implementation instead
of the majority of one-off, do-it-yourself I/O implementations that are
often susceptible to buffer overflows, off-by-one errors and the like.
In this case, the data structures appear to be easily convertible: a
std::vector for the string array, std::string for the individual
strings, and an std::fstream from which to read them. Of course putting
them all together is the fun part, so I won't spoil it with sample
code.
Greg