saving . . . saved i compiled it without any errors but when i ran it i got this error. has been deleted. i compiled it without any errors but when i ran it i got this error. has been hidden .
i compiled it without any errors but when i ran it i got this error.
Title
Question
code : -
#include<stdio.h>
#include<string.h>
int main()
{
char str1 [] = "best";
char str2 [] = "bus";
   printf("%s", strcat(str1, str2));
   return 0;
}

In terminal -
$ gcc strcat1.c -o strcat (without any errors)
$ ./strcat

output : -
*** stack smashing detected ***: terminated

Aborted (core dumped)


C-and-Cpp String-Library-Functions 06-07 min 30-40 sec 25-01-22, 2:33 p.m. Ravi_Ns

Answers:

Please try one more time. This code is running without any errors.
25-01-22, 5:11 p.m. hbammkanti

25-01-22, 8:11 p.m. Ravi_Ns

Login to add comment


corrected code : -

#include<stdio.h>
#include<string.h>
int main()
{
char str1 [10] = "best";
char str2 [10] = " bus";
strcat(str1, str2);
printf("%s\n", str1);
return 0;
}

note: strcat concatenate fist and second string and store data in first string.

*** stack smashing detected ***: terminated
This error occurs because of limited buffer memory that is there is not enough memory for both printf() and strcat(str1, str2) statements at same time.
25-01-22, 8:49 p.m. Ravi_Ns


Log-in to answer to this question.