c

How to generate an array of 8 bytes , each of these is random number in C

Hello, as in the title, and each element of the array iv should contain a random number between 0 and 255 . I have tried like: char iv[8]; char buf[2]; int i, k; srand(time(NULL)); for (i = 0; i <8; i++){ k = rand()%256; iv[i] = (char)k; } Thanks in advance. ...

UDP and sockets, recvfrom() returning -1 and resource temporarily unavailable

Hi, I'm pretty new at programming and esp network programming so if it's stupid, don't bash too hard please, thanks. I have client and server communicating with diagrams (UDP) in C. client sends 5 msgs and upon receiving msgs, server sends msgs back. receiving and sending messages are great until client has finished receiving the msgs. ...

Simple libtool alternative?

Being perfectly satisfied with old-style Makefiles, I am looking for a simple alternative to libtool. I do not want to switch to automake, and I keep running into problems with libtool when I try to use it directly. The latest one is 'unsupported hardcode properties', and I am getting fed up with the lack of complete documentation that j...

Unsigned Short to Unsigned Long assignment

Hi, While assigning from long to short, LSB 2 bytes is 0, where as MSB is filled with values from the func1() Algorithm values from stack. Why is this happening, why the compiler is trying to get these junk values to the MSB 2bytes? #include <stdio.h> unsigned short func1(void); // NB: function prototype ! int main(void) { uns...

How to cut a mpz_t into two parts using GMP lib on C?

Using GMP on c, I have a big integer "mpz_t n" in decimal form, how can I cut it into 2 parts? In fact, these 2 parts should have the same length in binary. For example, maybe I can convert the n to a binary of 112bits, then I want to cut it into 2 56bits parts. Thanks ...

What does "do { ... } while (0)" do exactly in kernel code?

Possible Duplicates: Whats the use of do while(0) when we define a macro? Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? C multi-line macro: do/while(0) vs scope block I have seen a lot of usages like this, previously I though that the programmer wanted to break out of a block of code...

C sprintf causing a segmentation fault.

Hello, I am trying to pass in arguments to the a parent file that is supposed to create a child process for each pair of arguments. The child processes will add up each pair and return their sum to the parent process. If there is an odd number of arguments passed in, I add a 0 to the end of the argv array to make it even. This keeps hap...

How can I convert an integer into a Unicode string in C?

I am working on the Firmware for an embedded USB project. The production programmer I would like to use automatically writes the Serial Number into the device flash memory at a specified memory address. The programmer stores the serial number as Hex digits in a specified number of bytes. For example, if I tell it to store the serial numb...

Reading and Writing Structures [C]

IMPORTANT EDIT: Sorry everyone, i made a big mistake in the structure. char *name; is meant to be outside of the structure, written to the file after the structure. This way, you read the structure, find out the size of the name, then read in the string. Also explains why there is no need for a null terminator. However, i feel somewhe...

A combined function for fprintf and write in c/c++

Hi, In C/C++, there is a 'write() function which let me write to either file or a socket, I just pass in the file descriptor accordingly). And there is a fprintf() which allow me to do fprintf (myFile, "hello %d", name); but it only works for file. Is there any api which allows me to do both? i.e. able to let me do print formatting an...

Pointer arithmetic and arrays: what's really legal?

Consider the following statements: int *pFarr, *pVarr; int farr[3] = {11,22,33}; int varr[3] = {7,8,9}; pFarr = &(farr[0]); pVarr = varr; At this stage, both pointers are pointing at the start of each respective array address. For *pFarr, we are presently looking at 11 and for *pVarr, 7. Equally, if I request the contents...

High volume SVM (machine learning) system

I working on a possible machine learning project that would be expected to do high speed computations for machine learning using SVM (support vector machines) and possibly some ANN. I'm resonably comfortable working on matlab with these, but primarly in small datasets, just for experimentation. I'm wondering if this matlab based approac...

How to put bits into a character Array

Hi, I need to know how to put bits into a character array. for example, I want to put 0001 bits into a character array using C or C++. Need your help guys. Thanks. ...

Swig alternatives for Ruby?

I am looking to generate ruby modules from existing C libraries. In the past, I have used Swig, and found that it was a painful task. I just want to check if there's something better for Ruby out there, and any gotchas. Just need to evaluate choices, so even a simple url pointing me to the site will do! ...

Binary name in java program compiled by gcj

Is there any way, from within a Java program compiled by gcj, to find out the name of the executable the user ran to start the program? In C, argv[0] (from inside main) is the name, but in Java, the args array given to main contains only the arguments to the main class. When running with a normal java command line, that makes some sense...

Backslash in the end of comment lines in C/C++

Does your editor/ide highlight that a++; in this C/C++ code as part of a comment? int a=1; //some comment \ a++; printf("%d\n",a); And what about this? int a=1; //some comment ??/ a++; printf("%d\n",a); ...

mysql_store_result() @ MySQL C API - does it really allocate memory in each call?

Hi! I've read that mysql_store_result() in the MySQL C API will allocate memory for each and every call to it; mysql_store_result() reads the entire result of a query to the client, allocates a MYSQL_RES structure, and places the result into this structure. It is really so? I'm asking because I'm about to call it many times in a serv...

how do i conbvert a gstreamer program to stream video via udp into Qt?

please help me convert this into a qt program. this is a gstreamer program to stream video via udp source. i need to implement this in Qt......the program i'm using is shown below.......... #include #include #include GstElement *pipeline, *source, *decoder, *video_s...

XOR using mathematical operators

How can I implement XOR using basic mathematical operators like +,-,*,/ Update: Actually, I need to track change in two matrix having Boolean values. This can be done using XORing each value with corresponding value in other matrix. But, Lp_Solve library doesn't support XOR operation. Also, it accepts only linear equations. ...

Different Types of Linked Lists!

What are the different types of Linked Lists which are commonly used? I know and have used the following: Singly Linked List Doubly Linked List Circular List What are the other kinds of lists that have been used by you or known to you? ...