c

Best Tools for 2D Constructive Area Geometry

What are the best tools/libraries (in any language) for working with 2D constructive area geometry? That is, a library working with more or less arbitrary two dimensional shapes and supplying union, intersection, difference and XOR. My baseline is the java.awt.geom.Area class, and that's serviceable if slow. What's out there that's ...

ferror(file) == 32

Sometimes, when I open the a file like so: FILE *file = fopen(fname, "wb"); if(!file) printf("Error code: %d\n",ferror(file)); I get a result of 32. What does this mean? Specifically, for eMbedded Visual C++ 4.0 Also, it seems like eVC does not support perror/errno :( Final Update: it seems like the underlying problem was with a la...

Verifying that memory has been initialized in C

I've written an API that requires a context to be initialized and thereafter passed into every API call. The caller allocates the memory for the context, and then passes it to the init function with other parameters that describe how they want later API calls to behave. The context is opaque, so the client can't really muck around in the...

Regex to pull out C function prototype declarations?

I'm somewhere on the learning curve when it comes to regular expressions, and I need to use them to automatically modify function prototypes in a bunch of C headers. Does anyone know of a decent regular expression to find any and all function prototypes in a C header, while excluding everything else? Edit: Three things that weren't cle...

How do *nix pseudo-terminals work ? What's the master/slave channel ?

I want to write a simple, dumb, X terminal emulator in C on a Linux system. At first, I just thought I would have to popen a shell and display its output. I checked xterm and rxvt code, and it looks a bit more complicated. First, I have to open a pseudo-terminal with openpty. So I look at the man page and see that openpty fills 2 file...

Converting C-DES-implementation to Java - Help needed

Hi, I'm a German student an for computer classes I need to implement the DES-encryption in Java(by myself, not by using the Java-API) and explain it in detail. I didn't find any Java-code-examples using google, however I did find an easy implementation in C(I do not know C, I know a little C++, but not that well, pointer still get me now...

What is the purpose of ungetc (or ungetch from K&R)?

Can anyone explain to me the purpose of ungetch? This is from K&R chapter 4 where you create a Reverse Polish Calculator. I've ran the program without the call to ungetch and in my tests it still works the same. int getch(void) /* get a (possibly pushed back) character */ { if (bufp > 0) { return buf[--bu...

Where is an array initialized by an initializer list stored?

Given this piece of code: (void)someFunction(void) { int array[] = {1,2,3,4,5,6,7,8,9,10}; } Where are the values of the array stored? Stack? Heap? Together with those string literals. (Is it called High Frequency Heap?) Somewhere else? I'm asking because I'm unsure regarding this question: Create an array of integers propert...

Predefined squareroot function without using sqrt() from math.h in C

Homework question: Cygwin GNU GDB Cygwin GNU GCC Attempting to establish the length of the hypotenuse C from the square root of A power of 2 and B power of 2. Example input: Enter the length of two sides of a right-angled triangle: 2.25 8.33 Answer: The length of the hypotenuse is: 8.628523 Question: when I specify the same i...

How do I write a C++ program that will easily compile in Linux and Windows?

I am making a C++ program. One of my biggest annoyances with C++ is its supposed platform independence. You all probably know that it is pretty much impossible to compile a Linux C++ program in Windows and a Windows one to Linux without a deluge of cryptic errors and platform specific include files. Of course you can always switch to ...

Parsing Integer to String C

How does one parse an integer to string(char* || char[]) in C? Is there an equivalent String parseInt(int) method from Java in C? ...

How to execute a command and get output of command within C++?

I am looking for a way to get the output of a command when it is run from within a C++ program. I have looked at using the system() function, but that will just execute a command. Here's an example of what I'm looking for: std::string result = system( "./some_command" ) ; I need to run an arbitrary command and get it's output. I've...

Requirements for Compiler Design

The student adviser we were working with is suddenly on leave. The plan was to design a compiler for a program which is similar to C (the basic structure of C still exists but keywords have been changed for example : for(i=0;i<10;i++) would now look like : loop i from 0 to 9 up 1 . And things such as #include have been omitted entirely...

flushing c input stream after every integer input

i have to make a user input num/percentage pairs. the code looks like: while(choice != 0) { printf("enter number"); fgets(line, sizeof(line), stdin);//sizeof(line) is 6 sscanf(line, "%d\n", choice); if(choice > 0) { printf("enter percentage\n"); fgets(percent_line, sizeof(percent_line), stdin);//sizeof(percent_line) = ...

function overloading in C

Is there any way to achieve function overloading in C? I am looking at simple functions to be overloaded like foo (int a) foo (char b) foo (float c , int d) I think there is no straight forward way, looking for workarounds if any? ...

How to compare compilers

What pointers do you use to compare between compilers? I'm told gcc is the best C compiler, is this true? If so, why? I mean this generally, so you can state which compiler is more appropriate for which architecture. (I hear igc would be more appropriate for Intel for instance, but I don't know why) Personally I intend to use AMD 64 ...

Is C# a superset of C?

Is C# a superset of C in anyway, like Objective-C or C++? Is there a way to compile C online with constructs such compiler flags? ...

Modifying C string constants?

I want to write a function that reverses the given string passed into it. But, I can not. If I supply the doReverse function (see code below) with a character array, my code works well. I can't figure out why this does not work. I am able to access str[0] in doReverse, but I can't change any value of the array by using a char pointer. A...

strange results of simple floating point operations - bad FPU internal state?

I have a software project in which I sometimes get strange results from small, simple floating point operations. I assume there is something I have missed, and would like some tips about how to debug the following problems: (the compiler used is MS VC 6.0, that is version 12 of the Microsoft C compiler) First anomaly: extern double ...

Windows Codepage Interactions with Standard C/C++ filenames?

A customer is complaining that our code used to write files with Japanese characters in the filename but no longer works in all cases. We have always just used good old char * strings to represent filenames, so it came as a bit of a shock to me that it ever worked, and we haven't done anything I am aware of that should have made it stop...