How to assemble a float from two bytes?

I am currently working on a project where I need to read out a DHT11 humidity and temperature sensor. The communication between the MCU and the serial device is quite low-level, but I managed to receive the measured values (humidity+temperature) as a...
more »

2017-05-20 11:05 (1) Answers

Storing element in string

Question: In my code, what ever I enter for n, compiler allows me to input and output only half of it. Why? #include<stdio.h> #include<stdlib.h> int main() { int n; scanf("%d\n",&n); char *c= (char*)malloc((n+1)*...
more »

2017-05-20 11:05 (2) Answers

Doesn't prints the entire array properly

Here is my code for an atm machine. It first asks the user for card number then Pin and then expiry date. char card_number[16]; memset(card_number,0,16); char pin[4]; memset(pin,0,4); char exp_date[5]; memset(exp_date,0,5); printf("Enter Card numbe...
more »

2017-05-20 02:05 (3) Answers

'Correct' unsigned integer comparison

So, we all know the C/C++ signed/unsigned comparison rules where -1 > 2u == true, and I have a situation where I want to implement 'correct' comparisons efficiently. My question is, which is more efficient with considerations to as many architect...
more »

2017-05-19 13:05 (7) Answers

Inconsistent output of quick sort

I want to experience worst case of quick sort. Therefore, I generate an array with descending order. After sorting with quick sort, array's first element sometimes becomes a garbage while sometimes becomes 0 as expected. When first element becomes a ...
more »

2017-05-19 00:05 (2) Answers

Header Inclusion Depth Limit

I was wondering, when including header files, can the depth of include files increase without limit? Can you specify a limit at compile time? Example: main.c: #include "A.h" const int xyz = CONST_VALUE; A.h: #include "B.h" B.h: #include "C....
more »

2017-05-18 21:05 (1) Answers

Difference extern"C" vs extern

Is there a difference whether I use the extern "C" specifier for the entire header, or specify extern for every function? As far as I know, there is none, since only functions and variables can be linked externally, so when I use the extern specifie...
more »

2017-05-18 21:05 (2) Answers

Ways of checking an unexpected user input

I have learned that one should never trust user's input. It has become an habit to check it before processing it. I use that type of functions almost always, and often wonders if there is a difference between those two versions. Here is a simple exa...
more »

2017-05-18 15:05 (1) Answers

Does bidirectional popen() work on Mac OS X in C?

My Question Where can I find a clear working example of C code that sets up and uses a bidirectional pipe with popen() on MacOS? I am trying to use popen() to open a bidirectional pipe between my C program and an external program on Mac OS X. My C...
more »

2017-05-18 10:05 (2) Answers

Why aren't there function headers in OCaml?

In certain programming languages, most notably in C, there are header files with function declarations. These function "headers" come before the code, and are required for situations with mutual recursion. When the function headers are placed in a he...
more »

2017-05-18 07:05 (3) Answers