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)
Aborted (core dumped)
C-and-Cpp String-Library-Functions 06-07 min 30-40 sec
Answers:
Please try one more time. This code is running without any errors.
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.
Login to add comment