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.
#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;
}
#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;
}
#include<stdio.h>
#include<conio.h>
void main()
{
char s1[10]="Best";
char s2[10]="Bus";
printf("concatenated string of %s and %s is %s",s1,s2,strcat(s1,s2));
getch();
}
output :
concatenated string of Best and Bus is BestBus
#include<stdio.h>
#include<conio.h>
void main()
{
char s1[10]="Best";
char s2[10]="Bus";
printf("concatenated string of %s and %s is %s",s1,s2,strcat(s1,s2));
getch();
}
#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;
}
#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;
}
#include<stdio.h>
#include<conio.h>
void main()
{
char str1[10]="best";
char str2[10]="bus";
printf("%s",strcat(str1,str2);
getch();
return 0;
}
output
bestbus
#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;
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[10]="best";
char str2[10]="bus";
printf("%s",strcat(str1,str2));
getch();
}
output:
bestbus
Login to add comment