c

Macro for iterating over a GList

I am using GLib's doubly linked list structure, GList. I would like to know if there is any standard macro for iterating over a GList. I couldn't find any such thing in the GLib documentation. As a result I have made my own macro, but I'd rather use something standard if it exists. To Illustrate the the issue: Usually I write a lot of c...

unable to pause the loop.. how?

void distinct (void) { char sent; int n1, n2, n3, n4, n5, n6, n7; FILE *fp2 = fopen ("distinct.txt", "w"); while (sent != 'n') { for (n1=2;n1<=9;n1++) { for (n2=2;n2<=9;n2++) { if (n2 != n1) { for (n3=2;n3<=9;n3++) { if (n3 != n2 && n3 != n1) { for (n4=2;n4<=9;n4++) { if (n4 != n3 && n4 != n2 && n4...

Size of int in C on different architectures

I am aware that the specification of the C language does not dictate the exact size of each integer type (e.g., int). What I am wondering is: Is there a way in C (not C++) to define an integer type with a specific size that ensures it will be the same across different architectures? Like: typedef int8 <an integer with 8 bits> typedef i...

Memory management and realloc

I'm going through my program with valgrind to hunt down memory leaks. Here's one that I'm not sure what to do with. ==15634== 500 (224 direct, 276 indirect) bytes in 2 blocks are definitely lost in loss record 73 of 392 ==15634== at 0x4007070: realloc (vg_replace_malloc.c:429) ==15634== by 0x807D5C2: hash_set_column(HASH*, int, ...

Why can't I use sizeof in a preprocessor condition ?

I understand that sizeof is an operator, which is evaluated at compile time to an integer constant. But it seem it can not be used in the #if preprocessor directive like: #if 4 == sizeof(int) typedef int Int32; #endif (cygwin-gcc 3.4.4 as well as Visual C++ 6.0 report compile errors) Why is such usage not allowed? ...

Uses of C comma operator

You see it used in for loop statements, but it's legal syntax anywhere. What uses have you found for it elsewhere, if any? ...

Get hex or octal value from escaped string

I'm working on an application that needs to accept posted data from a form and process it. One step of this process is to unescape the data that comes in. One issue that I'm facing is that the data I'm grabbing from the form is binary in nature so it includes escape sequences that I need to turn back into characters. This is fairly trivi...

Why was wchar_t invented?

Why is wchar_t needed? How is it superior to short (or __int16 or whatever)? (If it matters: I live in Windows world. I don't know what Linux does to support Unicode.) ...

Linux - serial port read returning EAGAIN...

Hello all! I am having some trouble reading some data from a serial port I opened the following way. I've used this instance of code plenty of times and all worked fine, but now, for some reason that I cant figure out, I am completely unable to read anything from the serial port. I am able to write and all is correctly received on the...

Create custom DNS name server in C

Need to create a custom DNS name server using C which will check against a mysql db to see if the client IP need to be directed to a different server. Using this for a test network so requests to foo.com will only go there if true lookup is enabled, otherwise requests will be directed to a development env. Any suggestions/recommendations...

how to determine which files has been changed from those in rcs

I am working with a c++ codebase using rcs repository (agh, old I know), during major code changes, I modify a lot of files, which I sometimes lose track of. So I would like to have a small script which will list the files that are different (those that I changed) from files in the repository. It is sort of unrealistic to do rcsdiff on...

C Endian Conversion : bit by bit

I have a special unsigned long (32 bits) and I need to convert the endianness of it bit by bit - my long represents several things all smooshed together into one piece of binary. How do I do it? ...

I Don't get the WM_GETMINMAXINFO message from other applications

Hello! In my C-Dll there is a Windows hook: hook = SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, hinstance, 0); With this Callback method: LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam) { ... CWPSTRUCT* cw = reinterpret_cast<CWPSTRUCT*>(lParam); myfile << "CallWndProc allg. " << cw->message << "\n"; if (cw->...

Why is this C code causing a segmentation fault?

I am trying to write code to reverse a string in place (I'm just trying to get better at C programming and pointer manipulation), but I cannot figure out why I am getting a segmentation fault: int main() { char* s = "teststring"; reverse(s); return 0; } reverse(char* s) { int i,j; char temp; for (i=0,j=(strlen...

OpenCV Grid Area

I want to find the non-white area of an image from a camera using OpenCV. I can already find circles using images from my web cam. I want to make a grid or something so I can determine the percent of the image is not white. Any ideas? ...

Why does my C++ divide program not compile

Hi all , i'm totally new to c++ ... i tried to make a program that have a correct Divide function ... my code was : #include <iostream> using namespace std; double x,y,z,a ; double divide (x,y) { if (x >= y){ x=z ; z=y ; y=x ; return(x/y); else r...

Is there a CPU that can change variables simultaneously?

if I write: a = 0; b = 0; c = 0; d = 0; e = 0; f = 0; I think (maybe am wrong) that the CPU will go line by line for example: CPU says: let me assign a to 0 then let me assign b to 0 then let me assign c to 0 then let me assign d to 0 etc... I was just wondering if there is a processor that can change variables simultaneously...? ...

Seeking a C Beautifier that will insert spaces between line elements.

I like spaces between almost all semantic elements in my C code. Thus I prefer if ( ( foo = bar ( arg1, arg2, arg3 ) ) == NULL ) { printf ( "Error 42" ); } to if((foo=bar(arg1,arg2,arg3))==NULL){ printf("Error 42"); } Is there a C beautifier around (unix platform) that can do this? It takes a seriously smart beautifier 'c...

C memory management for Cross-platform VM.

Hi all, I asked a question about C-type sizes which I get a pretty good answer but I realized that I may not formulate the question very well to be useful for my purpose. My background was from Computer Engineer before moves to Software Engineer so I like computer architectures and always thinking about making VM. I've just finished an ...

how to avoid writing main() too many times in C ?

Let say I have 5 small piece of codes in C. Every time I want to test each piece of code, I have to repeat this process: #include <stdio.h> int main() { // code piece go into here return 0; } Is there way that I don't have to do this 5 times? I'm using Code::Blocks, that means I have to create 5 different projects, which I beli...