There are two things wrong with your code. First, you
initialize a char*
with a string literal. This uses
a deprecated convertion; the type of a string literal is char
const[]
(which converts to char const*
, not to char*
),
because any attempt to modify the literal is undefined behavior.
The second is that your string literal is only one char
long,
so even if you could write to it, unless atr
was empty, you're
writing beyond the end of the buffer.
You don't tell us anything about parseargs
. If it doesn't
modify it's argument, you can just pass it atr.c_str()
, and be
done with it. (If it's a legacy function which ignores const,
you may have to use a const_cast
here.) If it does modify its
argument (say because it uses strtok
), then you'll have to
explicitly push a '\0'
onto the end of atr
, and then pass it
&atr[0]
. (Not a particularly clean solution, but if you're
not using atr
afterwards, it should work.)