Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Whenever I used strcat in my program, it crashes!?

crashes program Used
0
Posted

Whenever I used strcat in my program, it crashes!?

0

See, you probably want to ask what is wrong in the following code: printf (strcat (“Hello “, “World!”)); strcat appends the second argument to the first argument and returns the augmented first argument, but it does not allocate any extra space for doing this task. So, if you do strcat (“Hello “, “World!”); string “World!” will be copied over bytes which follows immidiately after bytes “Hello ” in the memory (whatever is there), which will nearly surely cause a crash (because there is probably a part of code or other data there). So, strcat may be used only when the first argument is enough long buffer, like in: char buffer[50]; strcpy (buffer, “Hello “); strcat (buffer, “World!”); In other words, C language does not support dynamic string manipulations which is present in some other languages like Basic, Turbo Pascal, etc.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123