Issue
#include<stdio.h>
int main()
{
char x[6];
scanf("%S",x);
printf("%S",x);
return 0;
}
The code is so simple and the output:
*** stack smashing detected ***: terminated
Even when I enter just one character, I know about the canary protection variable.
But does the compiler add that variable to my array or there is something else?
Solution
Use %s
format specifier, not %S
. And notice that a correct
prototype for main
is int main(void)
. Your code should be:
#include <stdio.h>
int main(void)
{
char x[6];
scanf("%s",x);
printf("%s\n",x);
return 0;
}
Use:
$ ./main
abc
abc
Answered By - Arkadiusz Drabczyk