How do I use extern to share variables between source files?

Using extern is only of relevance when the program you’re building consists of multiple source files linked together, where some of the variables defined, for example, in source file file1.c need to be referenced in other source files, such as file2.c. It is important to understand the difference between defining a variable and declaring a variable: A variable is declared when the compiler is informed that a … Read more

Printing long int value in C

You must use %ld to print a long int, and %lld to print a long long int. Note that only long long int is guaranteed to be large enough to store the result of that calculation (or, indeed, the input values you’re using). You will also need to ensure that you use your compiler in a C99-compatible mode (for example, using the -std=gnu99 option to … Read more

Categories C Tags

Fastest JSON reader/writer for C++

http://lloyd.github.com/yajl/ http://www.digip.org/jansson/ Don’t really know how they compare for speed, but the first one looks like the right idea for scaling to really big JSON data, since it parses only a small chunk at a time so they don’t need to hold all the data in memory at once (This can be faster or slower … Read more

How do I calculate MB/s & MiB/s?

If I transfer 1381530 bytes in 17797601 nanoseconds, what is the data rate in those two measures? 0.0776 bytes/ns. First, careful: I’ve recently discovered that MB/s is technically equivalent to 8000 million bits/s I’ve never heard of this definition. “MB/s” usually means “megabytes per second”. This can be one of two definitions, depending on who you ask: 1 … Read more

Categories C Tags

How to convert an int to string in C?

EDIT: As pointed out in the comment, itoa() is not a standard, so better use sprintf() approach suggested in the rivaling answer! You can use itoa() function to convert your integer value to a string. Here is an example: If you want to output your structure into a file there is no need to convert any value beforehand. You can just use … Read more

How do you do exponentiation in C?

use the pow function (it takes floats/doubles though). man pow: EDIT: For the special case of positive integer powers of 2, you can use bit shifting: (1 << x) will equal 2 to the power x. There are some potential gotchas with this, but generally, it would be correct.

Categories C Tags

How to divide 2 int in c?

You need a double variable to store the result. int stores only integers. Additionally, you have to typecast the other variables also before performing the division. Do something like this NOTE: You do not need the & in printf() statements.

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