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”

Python’s many ways of string formatting — are the older ones (going to be) deprecated?

The new .format() method is meant to replace the old % formatting syntax. The latter has been de-emphasised, (but not officially deprecated yet). The method documentation states as much: This method of string formatting is the new standard in Python 3, and should be preferred to the % formatting described in String Formatting Operations in … Read more

The “backspace” escape character ‘\b’: unexpected behavior?

Your result will vary depending on what kind of terminal or console program you’re on, but yes, on most \b is a nondestructive backspace. It moves the cursor backward, but doesn’t erase what’s there. So for the hello worl part, the code outputs hello worl ^ …(where ^ shows where the cursor is) Then it … Read more

Printing hexadecimal characters in C

You are seeing the ffffff because char is signed on your system. In C, vararg functions such as printf will promote all integers smaller than int to int. Since char is an integer (8-bit signed integer in your case), your chars are being promoted to int via sign-extension. Since c0 and 80 have a leading … Read more

Padding characters in printf

Pure Bash, no external utilities This demonstration does full justification, but you can just omit subtracting the length of the second string if you want ragged-right lines. pad=$(printf ‘%0.1s’ “-“{1..60}) padlength=40 string2=’bbbbbbb’ for string1 in a aa aaaa aaaaaaaa do printf ‘%s’ “$string1” printf ‘%*.*s’ 0 $((padlength – ${#string1} – ${#string2} )) “$pad” printf ‘%s\n’ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)