1
#include <stdio.h>

int main ()
{
    char a[10], b[9], c[5];
    scanf("%s", a);
    scanf("%s", b);
    scanf("%s", c);
    printf("%s\n", b);
    printf("%s %s %s", a, b, c);

    return 0;
}

when input c[] array's number > 5, the rest osf the characters will be wrriten to b[] array, why?

for example:

input: program is wonderful

output: rful program rful wonderful

Allen.W
  • 11
  • 1

1 Answers1

0

You're suffering C buffer overflow. Try to avoid using scanf("%s", char[]) for this purpose.

Better use fgets() or similar.

Offtopic: Interestingly this is related on how Nintendo's Wii was cracked. Or so it says the urban legend.

Jose Jurado
  • 301
  • 4
  • 7
  • Yes,I've learned that the way memory organise array in stack.It is wise that avoiding using scanf().Thanks for your advice. – Allen.W Aug 24 '15 at 15:09