How do the puts and gets functions work?

The problem here is, for an input like abc XYZ the code scanf(“%s”,name); reads only the “abc” part and the “XYZ” is left in the input buffer. The later gets() read that, and puts() prints that. As you don’t have a newline after the printf(), the output is not flushed and the outcome of the … Read more

Why is printf with a single argument (without conversion specifiers) deprecated?

printf(“Hello World!”); is IMHO not vulnerable but consider this: const char *str; … printf(str); If str happens to point to a string containing %s format specifiers, your program will exhibit undefined behaviour (mostly a crash), whereas puts(str) will just display the string as is. Example: printf(“%s”); //undefined behaviour (mostly crash) puts(“%s”); // displays “%s\n”