c

Initializing a char array in C. Which way is better?

The following are the two ways of initializing a char array: char charArray1[] = "foo"; char charArray2[] = {'f','o','o','\0'}; If both are equivalent, one would expect everyone to use the first option above (since it requires fewer key strokes). But I've seen code where the author takes the pain to always use the second method. My...

Pyramid program

One person is standing above the pyramid having 100 steps.He can take 1 or 2 steps at a time to come down.So there are how many possible ways he can come down? I want to solve this problemin c programming language Please Help to solve this problem ...

incrementing c pointers

i am using c pointers in which if i increment as *p++ it increments p but returns only the value which p pointed before it was incremented. how can i increment the value pointed by p. ...

Writing a list of data values to a .dat file to plot in GNUplot (in C)

Hiya, I have written two different methods to numerically differentiate a function and I am looking for a way to compare them. I have installed GNUPlot and would like to make a file (e.g. approximations.dat) for it to plot. At the moment my programn prints a series of columns with x-coordinate, approximation 1, approximation 2 and actu...

Is a C++ program really slower than a similar C program?

Assume that i have written a program in C++ without using RTTI and run-time polymorphism (no virtual function, no virtual inheritance) and classes don't have private/protected members, also the C++ specific header files are not used (i.e. C header files are used: cstring, cstdio, ... instead of string, iostream, ...). Then i want to wri...

libxml2 HTML parsing problems

I'm using libxml2 to parse HTML: static htmlSAXHandler simpleSAXHandlerStruct = { NULL, /* internalSubset */ NULL, /* isStandalone */ NULL, /* hasInternalSubset */ NULL, /* hasExternalSubset */ NULL, /* res...

Difficulty getting GDB to load debugging symbols

I use GDB to debug C/C++ programs very often, and I'm reasonably knowledgeable with how it works and what it can do. However, every so often I run into problems where mysteriously I can't seem to get GDB to properly load symbols from a core file. Currently, I have a binary executable in a shared NFS directory. The executable was def...

preprocessor directive

what exactly is a preprocessor directive .?? i do have an idea that #include is a preprocessor directive but what does it exactly do ..?? ...

Ensure all key events get sent to main window?

Is there a way to ensure that all WM_KEYDOWN events find their way into my main window regardless of who has focus? this is mainly for global things such as Delete, and hotkeys such as CTRL A and CTRL S. The problem is if another control has focus, all of these stop working. Is there maybe a better way of doing this than putting them in ...

Is void a data type in C?

Hi, Can I know if void is data type in "C"? what type of values it can store, if we have int, float, char etc to store the values why is void needed? ...

Pass pointer to guaranteed zeroed memory

I need to zero records of varying sizes in a file. To do this, I'm currently allocating dummy records, memseting them to zero, and passing these to a write function. Is there some region which is guaranteed to always be zeroed (and of a large enough size), that I can instead point to, removing the need for repeated allocation and zeroin...

Unexpected predefined macro behaviour when pasting tokens

The following (test with gcc -E blah.c): #define UNUSED(type) type UNUSED_ ## __COUNTER__ UNUSED(char const *) UNUSED(int) Generates: char const * UNUSED__COUNTER__ int UNUSED__COUNTER__ I'm expecting: char const * UNUSED0 int UNUSED1 I've tried calling another macro, wrapping the arguments in brackets to no avail. If I don't pa...

How to merge two linked lists in O(1) time in c?

Given two lists l1,l2, show how to merge them in O(1) time. The data structures for the lists depends on how you design it. By merging I mean to say union of the lists. Eg: List1 = {1,2,3} List2 = {2,4,5} Merged list = {1,2,3,4,5} ...

Integer vs floating division -> Who is responsible for providing the result?

I've been programming for a while in C++, but suddenly had a doubt and wanted to clarify with the Stackoverflow community. When an integer is divided by another integer, we all know the result is an integer and like wise, a float divided by float is also a float. But who is responsible for providing this result? Is it the compiler or D...

Borland c++ inline asm problem with WORD PTR and string

Hello, I am writing small kernel for the 8086 processor (Working in BC3.1, on Windows XP as host operating system). Kernel is multithreaded, so I have problems when I use printf or cout for debugging (somewhere in code, printf sets InterruptEnable flag to 1, and my timer interrupt routine calls dispatch and my code breaks down). Becaus...

Another question about C compiler asm output

Hi, very quick question for you. When I store some automatic variable in C, asm output is like this: MOV ESP+4,#25h , and I just want to know why can´t compiler calculate that ESP+4 adress itself. I thought this through, and I really cant find reason for this. I mean, isnt compiler aware of the esp value? It should be. And when using a...

The application failed to initalize properly (0xc0150002)

Hi, I have an image processing C program which uses OpenCV library. I was developping this with Visual Studio 2008 until this happened. So I moved the whole project to netbeans(6.9) and MinGW. I have configured netbeans to use OpenCV libraries as guided in this blog. But when I run the program it gives this error " The application fa...

How to reset static variables within a function

Is there a way to reset variables declared as static within a function? The goal is to make sure that the function is not called with lingering values from an unrelated call. For example, I have a function opearting on columns of a matrix. int foo(matrix *A, int colnum, int rownum){ static int whichColumn; static int *v; //vector of l...

Is alloca completely replaceable?

I've read quite a few places that alloca is obsolete and should not be used and Variable Length Arrays should be used instead. My question is this: Is alloca completely replaceable by variable length arrays? In my particular instance I have something that looks like this: typedef struct { int *value; size_t size; } some_typ...

codelite does not show the right directory structure while importing existing makefile based project

I have started using codelite as my c++ development IDE on Linux. I wanted to compile one of the makefile based project that I have. The directory structure of the project source code is this: src dirA dirC c.cpp a.cpp dirB b.cpp Makefile Now when I do import files from directory, I have to check box each direc...