c

Not able to solve the puzzle regarding this code.....

int i,n=20; for(i=0;i<n;i--) printf("-"); I have been rattling my brain but have not been able to solve this. Delete any single character or operator from above code and the program should print "-" 20 times Please help! ...

Array Division - What is the best way to divide two numbers stored in an array?

I have two arrays (dividend, divisor): dividend[] = {1,2,0,9,8,7,5,6,6}; divisor[] = {9,8}; I need the result (dividend/divisor) as: quotient[] = {1,2,3,4,5,6,7}; I did this using array subtraction: subtract divisor from dividend until dividend becomes 0 or less than divisor, each time incrementing quotient by 1, but it takes a...

Passing http form values to a C program

I've been assigned to upgrade an embedded application written in C. The application is configured via a web interface. When the user modifies the web application a file is written to /var/www/settings.json and the file /var/www/UPDATE_SETTINGS is touched. In the main application loop it checks to see if UPDATE_SETTINGS exists. If it do...

Two loop bodies or one (result identical)

I have long wondered what is more efficient with regards to making better use of CPU caches (which are known to benefit from locality of reference) - two loops each iterating over the same mathematical set of numbers, each with a different loop body, or having one loop that "concatenates" the two bodies into one, and thus accomplishes id...

How can I get an error stream over a socket in Java?

I'm currently writing something to work around this Java bug: http://bugs.sun.com/view_bug.do?bug_id=5049299 Basically, I've got a light weight C server that runs on the same machine as the Java server. I'm adding a feature to the C server when I can request it to fork/run a new process via a socket and pass back stdin/stdout/stderr. ...

Most efficient way to calculate the exponential of each element of a matrix

I'm migrating from Matlab to C + GSL and I would like to know what's the most efficient way to calculate the matrix B for which: B[i][j] = exp(A[i][j]) where i in [0, Ny] and j in [0, Nx]. Notice that this is different from matrix exponential: B = exp(A) which can be accomplished with some unstable/unsupported code in GSL (linalg....

What is an efficient way to convert a bignum type structure to a human readable string?

Hello all, I've got a bit of a problem. In order to grow in my knowledge of C, I've decided to try to implement a basic bigint library. The core of the bigint structure will be an array of 32 bit integers, chosen because they will fit in a register. This will allow me to do operations between digits that will overflow in a 64 bit integ...

Semi-inheritance in C: How does this snippet work?

Hi everyone, One way to hack limited form of polymorphism in C is to do something like this: typedef struct { int x; } base; typedef struct { base super; int y; } derived; Now you can refer to a derived instance as a base instance, depending on how the variable is cast, ie: derived my_derived; my_derived.y = 10; my_der...

Accept() function; Simple tcp server in C

I'm learning socket programming in C & downloaded a simple tcp server source file. I understand every line except the 2nd parameters in these functions: accept(socket_fd, (struct sockaddr *)&client, &length); bind(socket_fd, (struct sockaddr *)&server, length); The accept + bind functions are the typical functions in "sys/types.h" & ...

tries data structure implementation......... Application - Dictionary............

Hi, Wanted to write a program to implement a dictionary of words using Tries Data Structure. Please tell me the structure for the implementation so that I could start the program, as i haven't got any article on internet, for Tries Implementation.. The confusion is, that when we search through the word, and we get through the word at...

What does the '&' symbol in front of a variable do?

I've been going through some open-source code for a Twitter app, and came across this: (in the OADataFetcher.h) file: OAMutableURLRequest *request; NSURLResponse *response; NSError *error; NSData *responseData; (inside the 'fetchDataWithRequest:delegate:didFinishSelector:didFailSelector:' method) in OADataFetcher.m: responseData = ...

What is the difference between '__asm' and '__asm__'?

I am learning inline assembly in C. As far as I can tell, the only difference between __asm { ... }; and __asm__("..."); is that the first uses mov eax, var and the second uses movl %0, %%eax with :"=r" (var) at the end. Also, there are a lot less websites about the first. What other differences are there? ...

How can I make the Win32 API window more modern looking?

Hey, I ordered Programming Windows Fifth Edition a few days ago, and started working with it. I'm starting to learn the win32 api, however, I got a question. The windows do not look modern winxp/win vista/win 7 style at all. How do I fix this? It currently looks like this, crap font and all. Thanks in advance! Machiel ...

Efficient way of doing 64 bit rotate using 32 bit values

I need to rotate a 64 bit value using 2 32 bit registers. Has anyone come across an efficient way of doing this? ...

Compiling GCC 4.x.x on MinGW / MSYS Fails

I've been attempting for the last week or so to compile any of the GCC 4 series of compilers to run in MinGW 5.1.6 / MSYS 1.0.11 (automated installers both from Sourceforge.org) which ships with GCC version 3.4.5. The end goal is to get GCC 4.5 to install, but I haven't been able to get any of the 4.x.x compilers to build. I've narrowe...

C++: Fastest method to return a C string

I have a simple function that takes a char and return a string, in C it looks like; char* get_string(char c) { switch(c) { case 'A': return "some string"; Case 'B': return "some other string"; ... And it works fine, but then I wanted my code to work in C++, and the C++ compilers throws a gazillions "deprecated conversion fr...

How could this be done?

Given the following path: How could these smooth curves be generated given that the user provides the points and that cubic bezier is used? How would the control points or bezier handles be solved for, or how could I compute these points using cubic bezier given the user points above (the red squares) ? Basically I have an algorithm to...

groovy "def" declarations translates to C language?

i know this sounds totally ridiculous at the moment but trust me, i want something like "$variable" in php or "def" in groovy, by means of my approach is an automatic variable "data type" identification to IMPLEMENT into c language. for example: "def" is a replacement for a type name. In variable definitions it is used to indicate that...

Open Source VoIP/SIP Windows C API

It seems there is something for apple Open Source VoIP/SIP Objective-C Code Is there a similar stack for WIndows that anyone HAS EXPERIENCE with and is easy to implement? I have followed most of the leads here http://www.voip-info.org/wiki/view/Open+Source+VOIP+Software But they are abandoned or not a Standard windows C API. ...

Passing double types to ceil results in different values for different optimization levels in GCC

Below, the result1 and result2 variable values are reporting different values depending upon whether or not you compile the code with -g or with -O on GCC 4.2.1 and on GCC 3.2.0 (and I have not tried more recent GCC versions): double double_identity(double in_double) { return in_double; } ... double result1 = ceil(log(32.0) / log(...