c

Emulating/faking filesystem for testing C code?

I'm looking for the cross-platform way to test some features in my application which required access to the filesystem (to write and read binary data). In the real life my application running on Linux and store special data in /usr/local/etc directory. But main part of the application is cross-platform library and it should be tested bot...

Command-line C & keyboard shortcut (in Mac OS)

How can I execute a command when user press a key in a command-line C application? Is it possible when window isn't focused ...

Does "make" know how to search sub-dirs for include files?

Hello This is a question for experienced C/C++ developpers. I have zero knowledge of compiling C programs with "make", and need to modify an existing application, ie. change its "config" and "makefile" files. The .h files that the application needs are not located in a single-level directory, but rather, they are spread in multiple su...

I/O methods in C

Hi, I am looking for various ways of reading/writing data from stdin/stdout. Currently I know about scanf/printf, getchar/putchar and gets/puts. Are there any other ways of doing this? Also I am interesting in knowing that which one is most efficient in terms of Memory and Space. Thanks in Advance ...

C/C++ Dynamic loading of functions with unknown prototype

Hi, I'm in the process of writing a kind of runtime system/interpreter, and one of things that I need to be able to do is call c/c++ functions located in external libraries. On linux I'm using the dlfcn.h functions to open a library, and call a function located within. The problem is that, when using dlsysm() the function pointer retur...

Can scanf/sscanf deal with escaped characters?

int main() { char* a = " 'Fools\' day' "; char* b[64]; sscanf(a, " '%[^']s ", b); printf ("%s", b); } --> puts "Fools" in b Obviously, I want to have "Fools' day" in b. Can I tell sscanf() not to consider escaped apostrophes as the end of the character sequence? Thanks! ...

Please explain what this code is doing (someChar - 48)

i'm going through some practice problems, and i saw this code: #include <stdio.h> #include <string.h> int main(void) { char* s = "357"; int sum = 0; int i = 0; for (i = 0; i < strlen(s); i++) { sum += s[i] - 48; } printf("Sum is %d", sum); return 0; } can someone explain what the code does, especially the s...

What does the 2 stand for in fork(2) ?

What does the number in parentheses after C function name mean in manpages ? For instance, I see fork(2) and wonder what the 2 means... Also, I read things like pthread_atfork(3C), so what does the 3C stand for? ...

unix select() call: how to combine fd_sets?

I am writing an application in C for linux, which uses 2 separate third-party libraries. Both libraries are asynchronous and use select(). They also provide an API which returns the file descriptors they wait on. My intention is to pass these into my own select() and then return control back to whichever library when their own fd values ...

Algorithm for Audio - Video Encryption

Hi all, I want to perform encryption - decryption of certain audio - video files. Can anyone suggest me some suitable algorithms in cocoa, objective- c, c, or c++ to accomplish it? You can suggest me some link and/ or third party software for it. Thanks, Miraaj ...

converting contents of a "string array" AKA SAFEARRAY to wchar

I'm using WMI to read DefaultIPGateway on the WMI object Win32_NetworkAdapterConfiguration. The MSDN says it's a "String Array" and visual studio interprets this as a SAFEARRAY on the VARIANT object returned when you query the WMI. How do you access the information inside the array? How do you convert each element to a wchar* or char*? ...

Dynamically created UIView Objects

Hi all: I have a predicament, in as much that I need to create an arbitrary amount of UIView Objects. I have an NSArray and what I need to do is create UIView Objects for the number of items in the array, so I got an int from the [NSArray count]; method, so I know the number of objects needing creating, but the way to implement this has...

Compiling in constants at runtime

I have a program for some scientific simulation stuff, and as such needs to run quickly. When I started out, I was somewhat lazy, and decided to allow inputting constants later; and just used #define macros for them all. The problem is that when I tried changing that, it got a lot slower. For example, changing #define WIDTH 8 //.......

freeing substring without doing double free in c

Yesterday I asked a similar question regarding how to free allocated memory for a sub-string. Now I have one more question regarding the same problem (involving a set of conditions), how could I free the following sub-string without doing double free? #include <stdio.h> #include <stdlib.h> #include <string.h> struct st_ex { char pr...

Embedded Python - Blocking operations in time module

Hi all, I'm developing my own Python code interpreter using the Python C API, as described in the Python documentation. I've taken a look on the Python source code and I tried to follow the same steps that are carried out in the standard interpreter when executing a py file. These steps (sequence of C API function calls) are basically: ...

Make a 'press any key' routine that is compatible with redirected standard input

I've got a C/C++ program that runs in a console window, and prompts the user to press any key to continue, or 'q' to quit. It currently uses _kbhit() to detect if a key has been pressed, and then uses _getch() to determine what character it was. Now I want to be able to automate this program (from a C# app using a Process with RedirectS...

End of File(EOF) of Standard input stream (stdin)

Does stdin has any EOF? For e.g - If i start reading from stdin using fread/read then when the following loop will end? while ((c = read(0, buffer, BUFSIZ)) > 0) { . . . } If the solution of above is no the is there any way of added EOF in the stdin? ...

How can I store SpaceManager cpShape's in something like an array?

I'm trying to create a squishy ball with Cocos2d and Chipmunk (via SpaceManager) using a bunch of rects all chained together then joined with springs to a central body. Something like these examples But in order to do this, i think I need to store all the cpShapes in an array after I've created them so I can then loop through the arra...

Decompiling an ARM asm back to C

I wrote a nice ARM assembler routine a few years back and it has done its job beautifully over the years on the ARM embedded systems it was designed for. Now, the time has come to port it on to non-ARM systems and I was wondering if there was tool or some sort of method to take my original ARM assembler source and get a rudimentory C fi...

C threading in linux?

Does someone have a simple example of threading in c? I want to build a small console app that will read a txt file file line by line and then use threads to process the entire txt. How should I do this? splitting the txt into X where X=N of threads, is the first thing that comes to my mind, is there a better way? ...