How do you allow spaces to be entered using scanf?

People (and especially beginners) should never use scanf(“%s”) or gets() or any other functions that do not have buffer overflow protection, unless you know for certain that the input will always be of a specific format (and perhaps not even then). Remember than scanf stands for “scan formatted” and there’s precious little less formatted than … Read more

How I can print to stderr in C?

The syntax is almost the same as printf. With printf you give the string format and its contents ie: printf(“my %s has %d chars\n”, “string format”, 30); With fprintf it is the same, except now you are also specifying the place to print to: FILE *myFile; … fprintf( myFile, “my %s has %d chars\n”, “string … Read more

printf with std::string?

It’s compiling because printf isn’t type safe, since it uses variable arguments in the C sense1. printf has no option for std::string, only a C-style string. Using something else in place of what it expects definitely won’t give you the results you want. It’s actually undefined behaviour, so anything at all could happen. The easiest … Read more

Why use sprintf function in PHP?

sprintf has all the formatting capabilities of the original printf which means you can do much more than just inserting variable values in strings. For instance, specify number format (hex, decimal, octal), number of decimals, padding and more. Google for printf and you’ll find plenty of examples. The wikipedia article on printf should get you … Read more

What is the difference between conversion specifiers %i and %d in formatted IO functions (*printf / *scanf)

They are the same when used for output, e.g. with printf. However, these are different when used as input specifier e.g. with scanf, where %d scans an integer as a signed decimal number, but %i defaults to decimal but also allows hexadecimal (if preceded by 0x) and octal (if preceded by 0). So 033 would … Read more

How to print a float with 2 decimal places in Java?

You can use the printf method, like so: System.out.printf(“%.2f”, val); In short, the %.2f syntax tells Java to return your variable (val) with 2 decimal places (.2) in decimal representation of a floating-point number (f) from the start of the format specifier (%). There are other conversion characters you can use besides f: d: decimal … Read more

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