c

What is the Java equivalent of C's printf %g format specifier?

I tried using Formatter.format, but that seems to leave the mantissa on numbers with 0 mantissa, whereas the C version does not. Is there an equivalent of C's %g format specifier in Java, and if not, is there a way to fake it? My intention is to preserve the mantissa exactly like C's for compatibility reasons. foo.c #include <stdio.h> ...

How to truncate a file in C?

I'm using C to write some data to a file. I want to erase the previous text written in the file in case it was longer than what I'm writing now. I want to decrease the size of file or truncate until the end. How can I do this? ...

How do I clear this array pointer in C?

I'm trying do to a basic bash with the use of system calls but I'm having some little problems with a pointer array. To resume my code, I read commands from the stdin with read() to a buffer then I use strsep() to separate the command from the arguments and all the arguments into an array. Then I create a new process with fork() and exe...

How can I hook Windows functions in C/C++?

If I have a function foo() that windows has implemented in kernel32.dll and it always returns true, can I have my program: "bar.exe" hook/detour that Windows function and make it return false for all processes instead? So if my svchost, for example, calls foo(), it will return false instead of true. The same action should be expected fo...

Fastest C/C++ image resizing library

I am writing a application that needs to resize massive amounts of images... and these are my requirements C/C++ Support jpeg/png at least Fast Cross-Platform So far my options are OpenCV CImg ImageMagick GraphicsMagick (say their fast) DevIL GIL from Boost CxImage Imlib2 (say their fast) Any others? All of these would get the j...

[Updated] Is this a good substr for C?

See also C Tokenizer Here is a quick substr() for C that I wrote (yes, the variable initializations needs to be moved to start of the function etc, but you get the idea) I have seen many "smart" implementations of substr() that are simple one liner calls strncpy()! They are all wrong (strncpy does not guarantee null termination and t...

Properties file library for C (or C++)

The title is pretty self-explanatory: does anyone know of a (good) properties file reader library for C or, if not, C++? [Edit: To be specific, I want a library which handles the .properties file format used in Java: http://en.wikipedia.org/wiki/.properties] ...

C Tokenizer (and it returns empty too when fields are missing. yay!)

See also: Is this a good substr() for C? strtok() and friends skip over empty fields, and I do not know how to tell it not to skip but rather return empty in such cases. Similar behavior from most tokenizers I could see, and don't even get me started on sscanf() (but then it never said it would work on empty fields to begin with). I...

ftruncate trunc file in c cannot find this function

I want to truncate the file something like setsizeof() with FILE * I'm developing vs 2003 windows #include <unistd.h> there's no such lib how can I do it freopen() truncates all the data vut doesn't write- getting EINVAL error some help????? ...

Getting the name of a DLL from within the dll.

If I have a dll called "foo.dll" and the end user renames it to "bar.dll" and LoadLibrary's it, how can I get the name "bar.dll" from inside my dll? Is it GetModuleFilename(hModule, buffer); ? ...

When is it safe to destroy a pthread barrier?

If I have an initialised pthread_barrier_t, when is it safe to destroy it? Is the following example safe? pthread_barrier_t barrier; ... int rc = pthread_barrier_wait(b); if (rc != PTHREAD_BARRIER_SERIAL_THREAD && rc != 0){ perror("pthread_barrier_wait"); exit(1); } if (id == 0){ if(pthread_barrier_destroy(&(threads[t_root].info...

Supporting byte ordering in Linux user space

I'm writing a program on Linux in C to analyze core files produced from an embedded system. The core files might be little endian (ARM) or big endian (MIPS), and the program to analyze them might be running on a little endian host (x86) or big endian (PowerPC). By looking at the headers I know whether the core is LE or BE. I'd rather my...

How to copy a byte[] into a char*?

Hello, All I need this for is strcpy(). I want to see whether the first three bytes of a buffer(byte array) are "JMX" as string. This is what I did so far: char * ddj; strcpy( ddj, buffer ); //buffer is BYTE[] if ( strcmp( "JMX", ddj ) == 0 ) //check first three chars are "JMX" { buffer += 20; //increase the index with 20 s...

Regex for tree structures?

Are there regular expression equivalents for searching and modifying tree structures? Concise mini-languages (like perl regex) are what I am looking for. Here is an example that might clarify what I am looking for. <root> <node name="1"> subtrees .... </node> <node name="2"> <node name="2.1"> data </node> oth...

problems using the -ansi switch in MinGW 3.4.5

I was reading about the flags used in gcc, and read a reccommendation to use gcc -ansi -pedantic -Wall file1 [file2 [file3...]] -o output. For the quality of my code's sake, to keep it standard, and get all the warnings about it. Well, about compiling with -ansi... If I include <stdlib.h>, gcc gives me this error: In file included from...

Color generation function

Let's consider the following scenario: a function which can generate code colors from white to red, from white to blue, from white to pink, from white to orange, etc. The colors code is in RGB format with values from 0 to 255. Any ideas? Can you give me the pseudocode or link to such algorithm? ...

Does this multithreaded program perform better than the non-multithreaded one?

A colleague of mine asked me to write a homework for him. Although this wasn’t too ethical I did it, I plead guilty. This is how the problem goes: Write a program in C where the sequence 12 + 22 + ... + n2 is calculated. Assume that n is multiple of p and p is the number of threads. This is what I wrote: #include <pthread.h> #include <...

Linking extern variables in C

In Unix, I have got three main files. Ones of them as a library and the other one as a program. MyLib.c and MyLic.h are the library. main.c is the program. In MyLic.h I have a declaration (extern int Variable;). When I try to use Variable in main.c I cannot. Of course I have included "MyLib.h" in MyLib.c and in main.c, and I link th...

Writing PSRAM in EZ Flash 3 in 1

I am trying to figure out how to program the PSRAM in the GBA sized EZ Flash 3 in 1 card. Basically repeat what GBA Exploader and other programs do. If I select a block and program it then read it back the first halfword is always 0x1500 or something like that, but the rest of the data is fine. If on the write I select the previous ...

Microsoft SDL and memcpy deprecation

As some of you may know, Microsoft banned memcpy() from their Security Development Lifecycle, replacing it with memcpy_s(). void *memcpy(void *dest, const void *src, size_t n); /* simplified signature */ errno_t memcpy_s(void *dst, size_t dstsize, const void *src, size_t n); So if your code used to be: if (in_len > dst_len) { /*...