c

Create a new EXE from within C

Am working in VC++ 2008 (express) and I would like to write something in C that creates an "empty" exe that I can later call LoadLibrary on and use BeginUpdateResource, UpdateResource, EndUpdateResource to modify the contents. Just writing a 0-byte file doesn't allow me to open it with LoadLibrary because it isn't a resource. ...

Sorting blocks of L elements

I have an array of N * L integers int array[N * L]; I want to divide the array in N blocks of L elements and sort the blocks according to the classic list comparison (compare first element, than second, etc). In C I can do: qsort(array, N, sizeof(int) * L, comp); How can I achieve the same result using C++ std::sort(...) which is,...

Using || operator

Hi all, Am using a XML sort of language which doesnt have '||' operator. How can i achieve the effect of this operator? The language doesnt support ternary operator also. Other than if-else approach is there any other way to achieve this? The expression is, if((x == 2) || (y == 2)), and should achieve this without ||, ?: , if-else.. th...

Statement with no effect warning with GCC and Flex/Bison

When compiling my project with gcc and the -Wall option, I get a warning about a statement with no effect in the non-existant last line of my flex file: Warning: gcc -Wall -O0 -ggdb3 -DNOSUDO -DJOBC -DDEBUG -c lex.yy.c tokenizer.l: In function ‘yylex’: tokenizer.l:179: warning: statement with no effect Shell Command: $ wc -l tokeniz...

CreateTexture loading bitmap problem

I have the following function it takes 3 arguments being a texture array, filename and texture id but when I invoke the function using: CreateTexture(g_Texture, "\\\\nsq021vs\\u2\\abcb433\\MyDocs\\Visual Studio 2008\\Projects\\CaptainEdsAdv\\CaptainEdsAdv\\Back.bmp", BACK_ID ); it returns this: - pBitmap 0xcccccccc {sizeX=???...

Debugging unit test in C using check

I'm trying to use check unit testing framework for my C application. But I can't use the debugger (gdb) with it because of two points: first, check use some complex macros (START_TEST et END_TEST) and the debugger has trouble to put a breakpoint in my code between these two macros (in fact, I can put a software breakpoint but It is ne...

How do you set the order of libraries in automake?

How do you set the order of libraries in automake? In my am file I have something like: myprog_DEPENDENCIES = adhoc-target myprog_SOURCES = myprog.c myprog_LDADD = libmine.la myprog_LFLAGS = -static -L/home/user/lib -ladhoc Now, when I compile I get this compile line similar too: gcc -static myprog-myprog.o -o myprog -L/home/user/li...

Fake anonymous functions in C

In this SO thread, Brian Postow suggested a solution involving fake anonymous functions: make a comp(L) function that returns the version of comp for arrays of length L... that way L becomes a parameter, not a global How do I implement such a function? ...

strtok and execlp in a mini-shell

Hi fellows! I'm writing a mini-shell to get more familiar with Unix process management in C. It's reading stuff from commandline and passes these arguments via execlp to the system. # include <stdio.h> # include <stdlib.h> # include <unistd.h> #define MAXSIZE 100 char prompt[MAXSIZE]; int main(void){ pid_t pid; printf("> ...

Variable sized matrix in C

Is there any way to create a variable sized doubly-scripted array in C (not C++, just C)? I know that to create a variable sized singly-scripted array, you just use a pointer, e.g. float *array; array = (float *) calloc(sizeof(float), n); creates a singly-scripted array of floats of size n. Is there something similar that I can do for...

reading in numbers using strings

I need to code a function that will take in x numbers. (x is read into the function as an argument) The numbers can be preceded and separated by any number of white spaces and new-lines, and after the last number is entered, a new-line character ends the scan. I thought about using strings the take in characters, and to disregard any non...

Question about using windbg for a dll called from Labview

I am attempting to debug a dll that is called by a Labview application. I have the right symbol files (downloaded from microsoft) for things like ntdll.dll and others. I of course also have the pdb file for my DLL. What I don't have, obviously, is any symbol files for labview; since as far as I know National Instruments does not release....

Moving Active jobs in a Shell from the Background to Foreground and the Other Way Around

This section of the glibc manual explains job control, but unless I am missing it, it doesn't explain how to implement the ability to move a job that has already launched into the background or foreground. Can anyone give me a basic example, overview, or a link that explains how this works? I don't mean how to do this in a shell, but...

Why is GNU patch failing for this diff?

G'day, Edit: Just thought I'd mention that this somewhat long question is now fixed thanks to Adam Goode's answer below if you're just skimming while passing through. I've been given a patch to add to Apache 2.2.14 and one unified diff is not patching the file at all. I'm using GNU patch 2.5.4. I have to ignore whitespace because the ...

Why does C need arrays if it has pointers?

If we can use pointers and malloc to create and use arrays, why does the array type exist in C? Isn't it unnecessary if we can use pointers instead? Thanks. ...

Difference between statvfs() and statfs() system calls?

Why do the statfs() and statvfs() calls both exist when they're so similar? Under what circumstances would I prefer one over the other? ...

#define for unsigned long

Hi, I'm attempting to use the #define directive to change all of "ulong" to "unsigned long". Here is an example: #define ulong unsigned long ulong idCounter = 0; Sadly, I think it ends up replacing ulong with "unsigned", rather than "unsigned long". I tried "#define ulong (unsigned long)", but that didn't worth either. ...

Why is C and C++ IDE tool support behind what's available for managed platforms?

If you have used any decent java or .net IDE you can see the abundance of features that they provide that either do not exist in c/c++ IDEs or exist in a much more limited form. I am thinking about features like: Code Completion Syntax Errors (and compilation errors with no need to compile) Refactoring Debugging (the amount of informa...

Serialization/Deserialization of a struct to a char* in C

I have a struct struct Packet { int senderId; int sequenceNumber; char data[MaxDataSize]; char* Serialize() { char *message = new char[MaxMailSize]; message[0] = senderId; message[1] = sequenceNumber; for (unsigned i=0;i<MaxDataSize;i++) message[i+2] = data[i]; return ...

Dynamic memory allocation on stack

I recently tried this experiment in which instead of going for dynamic memory allocation for memory requirements of unknown size, I did a static allocation. When an array a[i] was declared by me, I kept i (size of the array) variable and dependent on the input that the user gives. #include <stdio.h> #include <stdlib.h> #include <stri...