/* gets() buffer overflow
* 2017-09-02
*/
#include <stdio.h>
#include<string.h>      // strncpy

struct Chars {
    char dest[10];
    char b[9];
};

int main(int argc, char **argv)
{
    struct Chars s;
    char junk;

    strncpy(s.b, "========", 9);
    printf("Begin: %s\nfgets() dest: ", s.b);
    fgets(s.dest, 10, stdin);
    printf("dest ->%s<-\nEnd: %s\n", s.dest, s.b);
    do {
        junk = getchar();
    } while (junk != '\n');

    strncpy(s.b, "========", 9);
    printf("Begin: %s\ngets() dest: ", s.b);
    gets(s.dest);
    printf("dest ->%s<-\nEnd: %s\n", s.dest, s.b);
    do {
        junk = getchar();
    } while (junk != '\n');

    return 0;
}