What is the most memory efficient way to search within a string in ANSI C? (put the code up)
An example where this is needed is in embedded devices that are very short on available memory but nowadays have reasonable clock cycles.
...
I have embedded a Python interpreter in a C program. Suppose the C program reads some bytes from a file into a char array and learns (somehow) that the bytes represent text with a certain encoding (e.g., ISO 8859-1, Windows-1252, or UTF-8). How do I decode the contents of this char array into a Python string?
The Python string should ...
I'm trying to compile a program called ngrep, and when I ran configure, things seemed to go well, but when I run make, I get:
ngrep.c: In function ‘process’:
ngrep.c:544: error: ‘struct udphdr’ has no member named ‘source’
ngrep.c:545: error: ‘struct udphdr’ has no member named ‘dest’
make: *** [ngrep.o] Error 1
What does that mean, a...
In Perl, I can type:
$|++;
and anything printed to STDOUT will be automatically fflush()ed.
Is there an equivalent in C? In other words, is there some way I can tell stdio to automatically fflush stdout after every printf(), the way it automatically flushes stderr?
...
On the Python side, I can create new numpy record arrays as follows:
numpy.zeros((3,), dtype=[('a', 'i4'), ('b', 'U5')])
How do I do the same from a C program? I suppose I have to call PyArray_SimpleNewFromDescr(nd, dims, descr), but how do I construct a PyArray_Descr that is appropriate for passing as the third argument to PyArray_S...
When I enable common control visual style support (InitCommonControls()) and I am using any theme other then Windows Classic Theme, buttons inside a group box appear with a black border with square corners.
Windows Classic Theme appears normal, as well as when I turn off visual styling.
I am using the following code:
group_box = Crea...
When I'm building a java object using JNI methods, in order to pass it in as a parameter to a java method I'm invoking using the JNI invocation API, how do I manage its memory?
Here's what I am working with:
I have a C object that has a destructor method that is more complex that free(). This C object is to be associated with a Java ...
What arbitrary-precision integers (and or rationals) library are there for compilers running on Microsoft Windows, and which would you recommend?
Please state license type / cost, supported compilers (i.e. GCC and or VC++) for the library.
...
I am trying to create a file in the /tmp directory (working on a Linux UBUNTU 7.10), that has read/write/execute access for any user. So I am using the "open(fileName,O_CREAT|O_RDWR,0777)" function to create the file (from a C program) in user1 account and I would like user2 to be able to write to the specific file.
However, when i chec...
How do I programmatically force the deletion of files that are locked by the operating system or any other program with C/C++? The functionality should be similar to the software "Unlocker" at http://ccollomb.free.fr/unlocker.
...
I'm getting a totally bizzare error trying to compile a C program using GCC. Here is the batch file I am using:
echo Now compiling, assembling, and linking the core:
nasm -f aout -o start.o start.asm
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o consoleio.o consoleio.c
g...
I've been thinking a lot lately about how to go about doing functional programming in C (not C++). Obviously, C is a procedural language and doesn't really support functional programming natively.
Are there any compiler/language extensions that add some functional programming constructs to the language? GCC provides nested functions a...
I wonder if there exist some free software that let me pass a C file and it outputs a more structured C-file.
I'm dealing with a short piece of C-Code that has been written long ago. I'd like to extract a clever algorithm from it, but working with the code itself is hard because it lacks everything that makes C-code readable.
Just a s...
As I understand it, when asked to reserve a larger block of memory, the realloc() function will do one of three different things:
if free contiguous block exists
grow current block
else if sufficient memory
allocate new memory
copy old memory to new
free old memory
else
return null
Growing the current block is a v...
I understand that "inline" by itself is a suggestion to the compiler, and at its descretion it may or may not inline the function, and it will also produce linkable object code.
I think that "static inline" does the same (may or may not inline) but will not produce linkable object code when inlined (since no other module could link to i...
I'm wondering about the practical use of #undef in C. I'm working through K&R, and am up to the preprocessor. Most of this was material I (more or less) understood, but something on page 90 (second edition) stuck out at me:
Names may be undefined with #undef,
usually to ensure that a routine is
really a function, not a macro:
...
As mentioned in many of my previous questions, I'm working through K&R, and am currently into the preprocessor. One of the more interesting things -- something I never knew before from any of my prior attempts to learn C -- is the ## preprocessor operator. According to K&R:
The preprocessor operator ##
provides a way to concatenate...
I've been having a lot of problems trying to figure out how to use scanf. It seems to work fine with integers, being fairly straight forward scanf("%d", &i).
Where I am running into issues is using scanf in loops trying to read input. For example:
do {
printf("counter: %d: ", counter);
scanf("%c %c%d", &command, &prefix, &input);...
OK, I feel very very stupid for getting hung up on such a basic concept, but I can't seem to find a difinitive answer for this question anywhere.
I'm in the process of trying to hack together the first bits of a kernel. I currently have the entire kernel compiled down as C code, and I've managed to get it displaying text in the console ...
Today when I was in computer organization class, teacher talked about something interesting to me. When it comes to talk about Why cache memory works, he said that:
for (i=0; i<M; i++)
for(j=0; j<N; j++)
X[i][j] = X[i][j] + K; //X is double(8 bytes)
it is not good to change the first line with the second. What is your opinion...