I dodmn't find anything about that in there. But getline()
isn't supposed to remove the newline characterr at the end,
see for example
http://pubs.opengroup.org/onlinepubs/9699919799/functions/getdelim.html
> I'm using fgets
You just said getline() and now it's fgets()? fgets() is a
different beast since it doesn't try to allocated memory
for the string but stops reading when the buffer is full
(but always makes sure there's a terminating '\0'). It
also doesn't remove the trailing linefeed (if one was
found and fit into the buffer).
> and strtok:
> port=::strtok(nullptr,"\n ");
In the first call of strtok() you must pass it the
address of the string it's to be working on. Only if
you want further snippets of what that string con-
tains you use a NULL pointer. If this is your very
first call of it then it probably will return a NULL
pointer (but since this case isn't documented it may
also crash the program or returns something else, no-
body can know who hasn't taken a closer look at how it
is implemented).
Note that the string you pass to strtok() must be
modifiable - strtok() changes it by replaces de-
limiters by '\0' in that string So you can't e.g.
use the result of applying the c_str() method on a
std::string! You'd have to make a copy in that case.
And if it's just for removing a trailing linefeed
it's probaly simpler to do just something like
if ( port[ strlen( port ) - 1 ] == '\n' )
port[ strlen( port ) - 1 ] = '\0';
What you get from getline() should never have more than
a single trailing '\n' (but it may have none if it read
the last line in a file and there wasn'tx one in that
last line).
Regards, Jens
--
\ Jens Thoms Toerring ___
j...@toerring.de
\__________________________
http://toerring.de