Get number of characters read by sscanf?

You can use the format specifier %n and provide an additional int * argument to sscanf(): int pos; sscanf(expression, “%lf%n”, &value, &pos); Description for format specifier n from the C99 standard: No input is consumed. The corresponding argument shall be a pointer to signed integer into which is to be written the number of characters … Read more

C program yielding different results on different machines despite using the same fixed length data types

It seems you might get this problem in case you are using a Windows compiler which uses Microsoft’s non-compliant CRT (non)standard library. That is: Visual Studio or Mingw64/gcc. I can reproduce it on Mingw/gcc. It’s a well-known problem that the Microsoft CRT is broken and for example doesn’t support various format specifiers introduced in C99. … Read more

What does the scanf function return?

From the man page: NAME scanf, fscanf, sscanf, vscanf, vsscanf, vfscanf … RETURN VALUE These functions return the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure. The value EOF is returned if the end of input is … Read more

C/C++ printf() before scanf() issue

Your output is being buffered. You have 4 options: explicit flush fflush after each write to profit from the buffer and still enforce the desiredbehavior/display explicitly. fflush( stdout ); have the buffer only buffer lines-wise useful for when you know that it is enough to print only complete lines setlinebuf(stdout); disable the buffer setbuf(stdout, NULL); … Read more

what is the Java equivalent of sscanf for parsing values from a string using a known pattern?

The problem is Java hasn’t out parameters (or passing by reference) as C or C#. But there is a better way (and more solid). Use regular expressions: Pattern p = Pattern.compile(“(\\d+)-(\\p{Alpha}+)-(\\d+) (\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)”) Matcher m = p.matcher(“17-MAR-11 15.52.25.000000000”); day = m.group(1); month= m.group(2); …. Of course C code is more concise, but this technique has one … Read more

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