Add a word to a string

Nov 28, 2008 at 5:01pm
How do I do to add a word (for example: car) the variable X[100] in the middle of the program?

X='car'

wont work :S
Nov 28, 2008 at 5:10pm
use double quotes x="car";
that will set x to "car", to add words use strcat() http://www.cplusplus.com/reference/clibrary/cstring/strcat.html
or the string class http://www.cplusplus.com/reference/string/string/
Nov 28, 2008 at 5:26pm
Thanks a lot,
I made it work with


char x[20]
(...)
strcpy(x,"car");

:D
Nov 28, 2008 at 6:45pm
Also take a look at strcat().

;-)
Nov 30, 2008 at 3:13am
Look at strcat() strcpy()
;)
Nov 30, 2008 at 7:15pm
IMO. snprintf() or strncpy() is the better one to use. strcpy() and strcat() is leaving yourself open to buffer overflows.
Topic archived. No new replies allowed.