I know I shouldn’t be using that function, and I don’t care. Last time I checked the spec for strcat, it said something along the lines of updating the first value as well as returning the same.
Now, this is a really stupid question, and I want you to explain it like you’re talking to a really stupid person.
Why won’t this work?
char* foo="foo";
printf(strcat(foo,"bar"));
EDIT: I don’t know the difference between char[] and char*. How would I allocate a string of 255 characters?
EDIT 2: OK, OK, so char[number] allocates a string of that many bytes? Makes sense. Thanks.
EDIT 3: Also, how would I use a character array without declaring it? Would I typecast it as char[255]?
EDIT 4: strcat((char[256])”foo”,”bar”) returns an error. I’m about fed up with C.
EDIT 5: So does strcat((char[256])”foo”,(char[])”bar”).
EDIT 5:
char[256] foo="bar";
Real smooth. “identifier expected”
is a string literal.
It can’t be modified. Do
char [] foo = "foo";instead but keep in mind that using strcat like that, will cause problems in this case cause it will write in memory it shouldn’t when trying tostrcat“bar” so you should try something likechar foo[30] = "foo";Edit: The typecasting you do… sorry I do not have so many brain cells as to try to explain you what you are trying to do. I can only tell you it is wrong. you need to provide a memory location so
strcat()can work.Try that :