SL points to a string literal, which has a size of one. For purposes of
backward compatibility, a pointer to such a string literal can be
assigned to a pointer to char. That, however, should never be done, as
it is not modifiable storage. So you have two problems.

1. You pass in this pointer to parse_usr_data(), which then attempts to
modify the buffer pointed to. That is undefined behavior.

2. Even if SL was modifiable, it can only hold one character.

You should be std::string rather than char*, and the verison of getline
that is not a member of the instream class:

* :
> Thanks to everyone. I may be stubborn but I've hard time to get it.
> The excuse is that it's just a few weeks I' fighting with C & C++.
>
> Anyway, I changed the declaration to:
>
> char Sl[1];
>
> and everything works fine.

Why don't you read the replies in the thread.

> Yes, I'm using g++.

That does not matter.

Cheers & hdh.,

- Alf

--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! Just going there is good. Linking
to it is even better! Thanks in advance!

wrote:
> Thanks to everyone. I may be stubborn but I've hard time to get it.
> The excuse is that it's just a few weeks I' fighting with C & C++.
>
> Anyway, I changed the declaration to:
>
> char Sl[1];
>
> and everything works fine.

Once again, you have a character array that can hold exactly one
character. That did not at all seem to be what you wanted. I doubt very
much that it is "working fine". It's just not as obviously broken as it
was before.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!