c

how to rewite a particular block of file

hello guys I want to rewrite a particular block in a file but its not working for me For example if I want to rewrite to offset 4 of the file I used lseek(fd,4,SEEK_SET) and called write system call but its writing at the end of the file instead of at offset 4. Can someone please help me. ...

How does Snipping Tool do this?

I noticed that Snipping Tool (On Windows Vista / 7) has a Toolbar control. I'v used Spy++ and copied its exact styles but when I press down, it does not do like theirs. Theirs stays stuck on the clicked control, indicating that this tool is 'in use' I want to have this effect in my application. Thanks ...

Skip to end of time quanta

Is it possible to skip to the end of a process's allocated time-quantum? I have a program that works in parallel on a piece of shared memory, and then all of the processes need to wait for the others to finish and sync up before the next step. Each process will do a maximum of one iteration more than any other, so any timing difference...

Allocating char array using malloc

Hi recently I saw a lot of code on online(also on SO;) like: char *p = malloc( sizeof(char) * ( len + 1 ) ); Why sizeof(char) ? It's not necessary, isn't it? Or Is it just a matter of style? What advantages does it have? ...

Killing the focus isn't killing the focus

Here is what I'm doing. I'v created a combobox but I'm not using it for that. When I click it, it calls trackpopup and brings up a context menu. However after I'v clicked the context menu, I'd like it to close the combobox in the same way it would if you clicked anywhere (killing the focus) or selected an item from the combobox. Here's ...

How many copies of console applications already launched

Hello. I have a console application, written on C. Inside this application, I want to determine how many copies of the console application are already launched. Thank you. ...

snmp agent libraries for C/C++?

I have to implement a performance statistics MIB for a linux based device and I am looking for a good agent development library. I came across net-snmp and agent++ libraries. I am looking for easier to understand and robust library. Which is the best library if usability and robustness is main criteria? ...

Store X.509 certificate in a c-string and load it into SSL_CTX object?

Hi experts, I'm pretty new to openssl. So far I've gone through tutorials offered by IBM and HP and got some practices about how to use openssl APIs. My project is about using a USB security memory token loaded with a digitial certificate to verify the identity of a client via an ActiveX control on the client's browser. Now the proble...

In C and C++, can I use macros definitions containing space?

Hello, I am wondering if macro definitions can contain space. Let's take for example this code: #define MACRO_PARAM int param2 int function(int param1, MACRO_PARAM) { return param1+param2; } This works ok with Visual Studio 8 and gcc 3.4.5 (mingw). For me this is good enough for the moment but is this standard? or can I rely on ...

Avoid duplicating code

Hi all, let's say I have: switch( choice ) { case A: stmt; do_stmt_related2A; break; case B: stmt; do_stmt_related2B; break; case C: something_different(); ... } How could I avoid duplicating stmt code? But is there any workaround? gcc extension label as value looks quite good for such situa...

Idiots Guide to compiling curl with ssh in Windows

Hello, I am not a c developer, but I have been asked to to compile curl with ssh. I have downloaded the source for curl, libssh2 and openssl. I have managed to compile curl within VS2008, but I have no idea on to add the libssh2 and openssl. Any help would be grateful. Thanks ...

Programming puzzle at CMU: how to find the location of process control block wrt base of the stack

I read a programming puzzle at CMU from the book Expert C programming: deep C secrets By Peter Van der Linden. The puzzle stated to code a program to read a file of numbers and print the average. The program must run as fast as possible and the program had to be written in PASCAL or C. It seems a programmer had created a program that a...

extern variables in static library, using Objective-C

Hello, I've built a static library, to be linked in my iPhone apps. This library uses some global variables and functions, like in C. My problem is, when using for example: extern void do_stuff (const int a) { return a*a; } extern const int a_variable; extern const int an_array[DEFINED_VALUE]; When I use this function, or access...

How is called a C/C++ program without end?

I mean a program based on events, a "static" program that don't just do a task but waits for events, etc. and doesn't end until the user manually close it. EDIT: I have answered below, for example the programs we use every day and are based in Windows, like Microsoft Word, Firefox, etc. What is this type of program called? How is it pos...

Why so many parentheses in SUCCEEDED macro?

Windows SDK features SUCCEEDED macro: #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) -----------------------^-------------^----- clearly as with other macros there're parentheses to ensure right interpretation of the intent by compiler. What I don't get is why there're parentheses around (HRESULT)(hr) (I marked them with ^ character). ...

How to declare a C struct with a pointer to array in ctypes?

Hi there, I read the official ctypes tutorial and also searched SO, but I could not find a way to declare this kind of structure with ctypes. This structure is returned by one of the functions I write an Python interface for. typedef struct{ int i; float *b1; float (*w1)[]; }foo; This is what I have so far: class foo(Str...

C library to encode/decode AMF

After googling a lot, I've found AMF libraries for PHP, Perl, Java, Python, Ruby... but none in C. Some of them have a C implementation, but it's too tied to the hosting language and they don't compile with a bare C compiler. Do you know of any pure C (or C++) implementation of AMF protocol? If not, which do you think would be the easie...

Redrawing a widget in Gtk.

I'm trying to redraw a GtkDrawingArea using the gtk_widget_queue_draw function, but the widget is not redrawing. Here's the code, the gtk_widget_queue_draw is inside a button-press-event callback function. static gboolean click(GtkWidget *board,GdkEventButton *event,gpointer parentWindow){ static int origen = -1; static int des...

Trouble implementing a real time program in C

I have a encoder which encodes a speech file(.wav) that i give as input. Now what i want to do is to write a program such that i can speak in the mic and at the same time the encoder can process it. Basically i want to record and process a speech signal in real time (a small delay can be tolerated). To do this i was thinking of making a ...

Getting each individual digit from a whole integer

Let's say I have an integer called 'score', that looks like this: int score = 1529587; Now what I want to do is get each digit 1, 5, 2, 9, 5, 8, 7 from the score using bitwise operators. I'm pretty sure this can be done since I've once used a similar method to extract the red green and blue values from a hexadecimal colour value. How...