Category "c"

Why should I always enable compiler warnings?

I often hear that when compiling C and C++ programs I should "always enable compiler warnings". Why is this necessary? How do I do that? Sometimes I also hear

Performance of built-in types : char vs short vs int vs. float vs. double

Seeing Alexandre C's reply in the other topic, I'm curious to know that if there is any performance difference with the built-in types: char vs short vs int vs

How to scp from a C program?

The following C program compiles and spits out a a directory listing of "/Users/home/tempdir" directory. #include <stdio.h> #include <unistd.h> i

AVR ATMEGA328 is Resetting when (TIMER1_CAP_VECT)Interrupt Occurs and sometime with the UART interrupt

I configure the ICP1 to get the pulses but when it happens, the avr is resetting, sometimes when the uart iterrput occurs it also reset. I don't know where I'm

while ((c = getchar()) != EOF) Not terminating

I've been reading "The C Programming Language" and I got to this part of inputs and outputs. I've read other threads saying that the console doesn't recognize e

X11: Detect general Mouse and Keyboard events

Is there a way to detect if the mouse has been moved ANYWHERE on the X Server or a keyboard event occured? I need to react on the user doing anything with the X

Embedding resources in executable using GCC

I'm looking for a way to easily embed any external binary data in a C/C++ application compiled by GCC. A good example of what I'd like to do is handling shader

How to find the socket connection state in C?

I have a TCP connection. Server just reads data from the client. Now, if the connection is lost, the client will get an error while writing the data to the pipe

Decrementing and incrementing a variable with an if condition produces unexpected result in C language

I'm running this code from the command prompt. The output of this code is 0 but I was expecting it to output 1. Can you explain how this code is actually compi

How can I know the version of c?

The "\b" didn't work on my Mac. So I tried to find the reason. I think that cause of this problem may be the version of C. Or device could be. If you know it, c

Why does fread always return 0?

I used this code to read file. But fread function always return 0. What is my mistake? FILE *file = fopen(pathToSourceFile, "rb"); if(file!=NULL) { char a

is it possible to do memcpy in bits instead of bytes?

I would like to know is it possible to do memcpy by bits instead of bytes? I am writing a C code for Ethernet frame with VLAN tagging, in which I need to fill

SDL2 How to draw dotted line

Is is just possible to draw a simple dotted line using SDL2 (or with gfx) like int drawDottedLine(SDL_Renderer *renderer,Sint16 x1,Sint16 y1, Sint16 x2, Sint1

Not able to remove a loadable kernel module

I'm writing a loadable kernel module and trying to test it. After inserting it I was trying to remove it using rmmod xxx command, but I get an error saying modu

SDL_TTF : undefined reference to "TTF_INIT"

I'm trying to learn how to use SDL_TTF library. But i'm unable to solve an error of type : undefined reference to "TTF_INIT" here is the simple code that im t

Draw the midpoint lines between points

I am making generated shapes in a fragment shader and part of it involves drawing the border between objects ie the dividing line between them. Currently I have

What is the difference between exit and return?

What is difference between return and exit statement in C programming when called from anywhere in a C program?

Static assert in C

What's the best way to achieve compile time static asserts in C (not C++), with particular emphasis on GCC?

What is the simplest way of implementing bigint in C?

I am trying to calculate 100! (that is, the factorial of 100). I am looking for the simplest way to accomplish this using C. I have read around but have not fou

Finding consecutive bit string of 1 or 0

How to find the length of the longest consecutive bit string(either 1 or 0)? 00000000 11110000 00000000 00000000 -> If it is 0 then length will be 20 111