c

Loading and storing encryption keys from a config source

I am writing an application which has an authenticity mechanism, using HMAC-sha1, plus a CBC-blowfish pass over the data for good measure. This requires 2 keys and one ivec. I have looked at Crypto++ but the documentation is very poor (for example the HMAC documentation). So I am going oldschool and use Openssl. Whats the best way to g...

What are the differences between break and exit?

Even I used break() and exit() statements many times, I am bit confused between them. I need to know exact meaning of both, when we should use them. Please explain with small example. Thank you. ...

Hashtable implementation for C

what is a good hashtable implementation for C? I need to use it with mpicc compiler. Delete function is not necessary. ...

How do I convert text to XML in C?

How can I make a program that opens a text file, and converts it into a XML file? The XML might look like: <curso> <sigla>LTCGM</sigla> <NAlunos>1</NAlunos> <lista_alunos> <aluno> <numero>6567</numero> <nome>Artur Pereira Ribeiro</nome> <email>[email protected]</email> <estado>Aprovado</estado> <media_notas>13</med...

Recursive main() - why does it segfault?

Why does the following program segfault? int main() { main(); } Even though it is a recursion that does not end and is therefore invalid by definition, I don't see why it segfaults (gcc 4.4.3 and clang 1.5 (trunk)). ...

Which loop configuration will take more time to run?

Code I: for(i=0; i<100; i++){ for(j=0; j<1000; j++){ x = y; } } Code II: for(i=0; i<1000; i++){ for(j=0; j<100; j++){ x = y; } } Can you explain why one of these loop configurations will take more time to run than the other? ...

How to define 2-bit numbers in C, if possible?

For my university process I'm simulating a process called random sequential adsorption. One of the things I have to do involves randomly depositing squares (which cannot overlap) onto a lattice until there is no more room left, repeating the process several times in order to find the average 'jamming' coverage %. Basically I'm performi...

forkpty - socket

Hi, I'm trying to develop a simple "telnet/server" daemon which have to run a program on a new socket connection. This part working fine. But I have to associate my new process to a pty, because this process have some terminal capabilities (like a readline). The code I've developped is (where socketfd is the new socket file descriptor...

What is a simple C library for a set of integer sets?

I've got to modify a C program and I need to include a set of unsigned integer sets. That is, I have millions of sets of integers (each of these integer sets contains between 3 and 100 integers), and I need to store these in some structure, lets call it the directory, that can in logarithmic time tell me whether a given integer set alre...

Parse and read data frame in C?

I am writing a program that reads the data from the serial port on Linux. The data are sent by another device with the following frame format: |start | Command | Data | CRC | End | |0x02 | 0x41 | (0-127 octets) | | 0x03| ---------------------------------------------------- The Data field contains 127 octet...

c struct pointer issues

I'm trying to cast a struct into another struct but I'm having incompatible pointer issues within the cast and the malloc under some_func (structs layout are the same) struct stu1 **some_func(struct stu1 *my_struct) { my_struct = (struct stu1 **)malloc(sizeof(struct stu1 *)*total_size); for(i=0;i<20;i++){ my_struct[i] = (st...

Is there any algorithm for turning simple HAXE code into C/C++ code files?

I have simple Haxe app like class Main { public static function main() { trace("hello world"); } } I know how to compile such app for windows (not as SWF but as app from pure C\C++ )(and you can see how here but be worned thay use hxcpp\0,4 ) The problem is - I do not want to compile app for Windows Vista or 7 or XP I want to get PUR...

Get BoundingBox of a transparent Image?

Hi, i load a transparent .png into an UIImage. How to i calculte the real bounding-box. E.g. if the the real image is smaller than the .png-dimensions. Thanks for helping ...

Declaring a prototype of type "struct" - C

I've been racking my brains on this for a while, I'm simply trying to create a method that returns a struct as I wish to return two int's. My prototype for the method is as follows: typedef struct RollDice(); Also the method itself: typedef struct RollDice() { diceData diceRoll; diceRoll.dice1 = 0; diceRoll.dice2 = 0; return d...

safely reading directory contents

Is it safe to read directory entries via readdir() or scandir() while files are being created/deleted in this directory? Should I prefer one over the other? EDIT: When I say "safe" I mean entries returned by these functions are valid and can be operated without crushing the program. Thanks. ...

ftell( stdin ) causes illegal seek error

The following code outputs "Illegal seek": #include <stdio.h> #include <errno.h> #include <string.h> int main() { errno = 0; getchar(); getchar(); getchar(); ftell( stdin ); printf( "%s\n", strerror(errno) ); } This occurs when I run "cat script | ./a.out" as well as when I just run "./a.out". The problem is...

What can I do with an enum variable?

When I declare a enum variable like this: enum paint_colors { RED, GREEN, BLUE, ...} colors; is the colors variable useful? If so, what can I do with it? Thanks in advance. ...

C Language Standard Collections Where Are They?

I have committed to learning C now, I'm good with Python/PHP/Bash but I've decided I'm limited by not being fluent in C. However I cannot imagine working in a language without lists and hashes, maybe I'm just jumping a gun, but surely there are 'standard' collection libraries. I do not see any in the GNU standard lib though, any sugges...

Structuring leafs in a hierarchical tree

This code fills a tree with values based on their depths. But when traversing the tree, I cannot manage to determine the actual number of children without iterating over the parent node. This is necessary because the subleafs are stored in in the node underneath the current one. Which conceptual changes are necessary to store the leafs d...

C preprocessor at run time?

Hi guys, I want to do a Token concatenation, but I want to do this with the content of a variable, not its name. like this. #define call_function(fun, number) fun##_##number () while (i < 10 ) { call_function(fun, i); } but I give fun_number (), I want to give fun_1, fun_2, and so on... how to do it? About function pointers. I'...