c

C: Obfuscating an integer

If I have an integer like this in several places in my code... int my_secret = 42; ... is it possible to make it more difficult to find that integer in the compiled program? I've seen this done with strings, for example by shifting each letter by x characters and then un-shifting them at runtime, but I doubt this technique would work ...

Using Eclipse for C programming?

I want to examine and modify some open source programs written in C. Is it sensible to use Eclipse for this purpose? If so, what plugins should I add? What "gotchas" should I be aware of? If not, what FOSS C IDEs do you recommend for coding C on a linux box? Emacs, while undeniably powerful, is not to my taste (I'm more a mouser than a...

How to walk a directory in C

I am using glib in my application, and I see there are convenience wrappers in glib for C's remove, unlink and rmdir. But these only work on a single file or directory at a time. As far as I can see, neither the C standard nor glib include any sort of recursive directory walk functionality. Nor do I see any specific way to delete an ent...

ANSI C: How to split a string by newline and get a random line

Hi, I'm a new to C and got stuck with subj. I can split string with strtok but I don't know how to get a random token. Thanks. ...

Counting Syllables one char at a time [C]

I'm writing a program which reads text from a file, and determines the number of sentences, words, and syllables of that file. The trick is, it must only read one character a time, and work with that. Which means it can't just store the whole file in an array. So, with that in mind, heres how my program works: while(character != EOF) {...

Pointer type conversion: effect on buffer length?

Char is 1 byte unsigned short is 2 bytes So if I cast a char * to unsigned short *, will it change the length of the buffer? For example I am passing char * and length to a VUMeter function. The function casts the char * to unsigned short *: short* pln = (short*) buffer;` Now I loop through the buffer, so can I use same length which...

How do you write a bigint library / how does libgmp work?

Hi All, I'm aware of a number of BigInt libraries for C on various platforms and how to use them but I'm intrigued: how do they work? How would I go about building my own library (I'm not going to try, no point re-inventing the wheel but I'm interested in how it might happen)? Can anyone point me towards tutorials etc that might explain...

Cygwin gcc compiled fails in IDE complaining about 'exit' undeclared

When I compile a program using just gcc code.c There are no messages, and an output file is generated successfully. The outputted file works. However, when I try to the same cygwin installation's gcc compiler in an IDE (I've tried Netbeans and Dev-C++), I get the following errors main.cpp:27: error: `exit' undeclared (first use this ...

Why does a function need to be declared before it's defined or used?

In C its optional. In C++ one "MUST" declare a function before its used/defined. Why is it so? Whats the need? We don't do that in C# or Java. Funny thing is while we are defining a function. The definition itself has a declaration even then, we need to declare. God knows why? ...

c console window title

How to set the console window title in C? printf("%c]0;%s%c", '\033', "My Console Title", '\007'); This works only under linux, not in windows, Does anybody know a "cross-platform" solution? (of course not "system ( title=blah )") ...

concatenate char array in C

I have a a char array: char* name = "hello"; I want to add an extension to that name to make it hello.txt How can I do this? name += ".txt" won't work ...

Why before ALL functions (except for main()) there is a 'static' keyword ?

I was reading some source code files in C and C++ (mainly C)... I know the meaning of 'static' keyword is that static functions are functions that are only visible to other functions in the same file. In another context I read up it's nice to use static functions in cases where we don't want them to be used outside from the file they are...

using OpenGL ES on FPGA xilinx

Hi everybody! I want to know if it is possible to use OpenGl ES on Xilinx to developp a 3D application. thanks! ...

Extension of Binary search algo to find the first and last index of the key value to be searched in an array.

The problem is to extend the binary search algorithm to find all occurrences of a target value in a sorted array in the most efficient way. Concretely speaking, the input of the algorithm are (1) a sorted array of integers, where some numbers may appear more than once, and (2) a target integer to be searched. The output of the algorithm...

Rounding to an integer - Rounding control field?

I am trying to write a function named roundD that rounds its first argument to an integer value according to the mode specified by its second argument. I will be writing the function in assembly language, using gcc’s inline assembler. I do not want to use any predefined functions.. I think i need to set the Rounding Control field of t...

Going for an scripting language from C world

I came from a C-Java-C# world... where the parentheses were VIP citizens and types were loved by everyone : ) Sometimes I need to develop some piece of code to automatize a repetitive task, convert some complex frame, order an input file, send programatic request to a server... you know what I mean? But sometimes I wonder how easier c...

How to initialize const members of structs on the heap

I would like to allocate a structure on the heap, initialize it and return a pointer to it from a function. I'm wondering if there's a way for me to initialize const members of a struct in this scenario: #include <stdlib.h> typedef struct { const int x; const int y; } ImmutablePoint; ImmutablePoint * make_immutable_point(int x, in...

Duplicate image detection algorithms?

I am thinking about creating a database system for images where they are stored with compact signatures and then matched against a "query image" that could be a resized, cropped, brightened, rotated or a flipped version of the stored one. Note that I am not talking about image similarity algorithms but rather strictly about duplicate det...

Dealing with Floating Point exceptions

Hi, I am not sure how to deal with floating point exceptions in either C or C++. From wiki, there are following types of floating point exceptions: IEEE 754 specifies five arithmetic errors that are to be recorded in "sticky bits" (by default; note that trapping and other alternatives are optional and, if provided, non-default). * ...

How to implement alarm() method correctly to kill all worker processes created by fork()?

If I have a parent coordinator program and a worker program, but the coordinator program is creating all of the needed worker processes. If I want to implement the alarm() method correctly to kill all of the processes and terminate the program after a certain amount of time. Is this the correct way to implement it? The current way I hav...