c

Implementation for Bresenham's ellipse drawing algorithm in OpenGL

I'm looking for one to build a MS-paint like app. ...

Tail recursion in C

I was trying to write recursion function,to find factorial of a number. int factorial(int input,int *answer) { if ( input ==0 ) { return 0; } *answer = *answer * input; factorial(input -1, answer); } What will you say about this function? Is it tai...

Qt4 Wrapper results in Segmentation fault(s)

I'm currently writing a set of wrapper functions of Qt4 for an application as plugin (because I personally think that writing extensions in plain C is easier to accomplish). At first I though this could be done by simply abstracting the following: #include <QApplication> #include <QPushButton> int main(int argc, char *argv[]) { QA...

What's a good Wordpress extension for coloring C/C++/script code?

My research group uses a Wordpress blog. Frequently I want post snippets or even entire short programs I've been working on to it, with most of my code being written in C/C++ or scripting languages (Bash, TCL, etc). I figure that there have to be some good extensions to Wordpress to colorify code since so many people use it. I'm loo...

Parsing a stream of data for control strings

I feel like this is a pretty common problem but I wasn't really sure what to search for. I have a large file (so I don't want to load it all into memory) that I need to parse control strings out of and then stream that data to another computer. I'm currently reading in the file in 1000 byte chunks. So for example if I have a string tha...

What does the C function bit_get do in DES encryption?

Hi there, I stumbled upon this piece of code while reading about DES encryption. I wonder what it does do exactly? I see that it returns either 1 or 0 according to the result of the last if. I also understand that mask is in hexadecimal and equals 128 in decimal (why this particular value?). The for loop starts from 0 until pos%8, why?...

When using a restrict Pointer in C, is it OK to change a variable using its initial Identifier?

When using a restrict Pointer in C, is it OK to change the variable using its initial Identifier? For example: int foo = 0; int * restrict fooPtr = &foo; ++(*fooPtr); // Part 1: foo is 1 (OK) ++foo; // Part 2: foo is 2 (Is this OK?) int * fooPtr2 = &foo; ++(*fooPtr2); // Par...

How to store a string from a text file in an array in C

I want to read a text file into a string array and be able to access the array contents through a loop. The code I have allows me to store only the last line of the text file instead of the entire file; where am I going wrong? #define MAX 10000 int main (int argc, char *argv[]) { FILE *fp; char str[MAX]; char *x[MAX]; i...

Is there a glibc hash function?

Hey, I'm looking to do a custom hash table implementation in C. Is there an MD5/SHA1 hash function already in the GNU library or do I have to use an external library for this? Here's kinda what I'm looking for: int hashValue; hashValue = MD5_HASH(valToHash); ...

Best/common practice to delimit values in C when printing them.

I tried the search function but only found questions regarding reading in comma/space delimited files. My question is however, how do you usually approach this. Say I have a list/array/... of values, like {1, 2, 3, 4} and want to print them with a delimiter. The simplest version would be something like: #include <stdio.h> int main(...

Undefined Variable error

Hi, I'm a newbie to programming in C, and I'm having trouble understanding the error that is coming up when I attempt to compile my program. I've got the following program, which is fairly simple and which my professor says is correct: #include <stdio.h> #define TRUE 1 #define FALSE 0 #define BOOL int extern int x; extern BOOL do_exp; ...

Network receipt timer to ms resolution

My scenario, I'm collecting network packets and if packets match a network filter I want to record the time difference between consecutive packets, this last part is the part that doesn't work. My problem is that I cant get accurate sub-second measurements no matter what C timer function I use. I've tried: gettimeofday(), clock_gettime...

How can I write commands to the vxworks shell with a c program

If I wanted to run a shell command in linux with a c program, I would use system("ls"); Is there a way I can accomplish this in Wind River vxworks? I found the below example but I'm wondering do I need to include vxworks header files for this to work? I assume I do, but how do I figure out which one? Example: // This function runs...

Error and unexpected behavior with TCP connection

hi.. I am wanting my TCP server and client to "talk" to each other depending on what the other says. But when I run, it seems to go through one iteration, but then both the server and client seem to just "hang" there. Once I kill it on the client side, I end up getting a broken pipe error. Can anyone interpret what I am doing wrong he...

How do I make a human-readable string out of a struct tm?

Hello, I am getting a struct tm and I want to convert it into a string with this specific output: dd-mm-yyyy hh:mm where everything is a number except for the month (mm), such as: 14-Oct-2010 10:35 This is my current code: struct stat sb; if (lstat(path, &sb) == 0) { struct tm *pmytm = gmtime(&sb.st_mtime); sprintf(arra...

Throwing an exception instead of error from a PHP extension

Another co-worker and I have been heavily modifying the PHP Zookeeper extension but the one thing really bothering me is the reliance on PHP error's vs Exceptions. The original source is here: http://github.com/andreiz/php-zookeeper/blob/master/php_zookeeper.c#L209 Instead it would be nicer to throw up a Zookeeper_NodeNotExists or simi...

Why isn't this bresenham line appearing where it should?

I'm writing a MS paint-like application (I'm not allowed to use opengl primitives). So far it only draws lines and points. I don't understand why when rendering a single point on click this code prints it where it should, based on the transformation on the renderPoint function: void renderPoint(double x, double y) { W = glut...

How to create sound from an array of double and play it on speaker.

I have an array of double (size more than 60k entries), I have the frequency value. Now I want to create a sound from it using C/C++ which I can play on speaker. My OS is linux. Thanks. I hope I am clear enough. ...

reading data from memory in C from within an Objective C class

I would like to know if it is possible to read and write data from and to memory with ANSI C code instead of from a file. I have C code that is called from within an Objective C class many times and each time, it has to read in the same large binary file, do some processing on it, and then write out a large binary file (which is slightl...

Memory and pointers

Hi I have need some some help with some thinking around a task. My task is to create one memory area void *memory = malloc(320); and then use pointers to store texts into this storage place: We want to divide this area into data blocks of 32 bytes, sow we can store: 320/32 = 10 data blocks a 32 bytes. Into one data block I can store...