c

Problems with Erlang NIF and threads

Hi. I have a little problem with threads in Erlang NIFs. You can view my code here: http://pastebin.com/HMCj24Jp. The problem is that when I starting the thread it takes some arguments and starts the generate_binary function. This is okay but when I'm trying to read the arguments everything crashes. It's perhaps not the most complex pr...

Set environment variables in C

Hi, Is there anyway to set environment variables in linux using C? I tried setenv() and putenv(), but they don't seem to be working for me. Thanks in advance. ...

WinINet asynchronous mode disaster

Sorry for such a long question. It's just I've spent several days trying to solve my problem, and I'm exhausted. I'm trying to use WinINet in an asynchronous mode. And I must say... this is simply insane. I really can't understand this. It does so many things, but unfortunately its asynchronous API is so much poorly designed that it jus...

Sending char pointer with UDP in C

I have a struct that I am sending to a UDP socket: typedef struct { char field_id; short field_length; char* field; } field_t, *field_p; I am able to read the field_id and field_length once received on the UDP server-side, however the pointer to field is invalid as expected. What is the best method to properly send and re...

Perl system call causes core dump but $? remains zero

I've got a Perl script (running on Xubuntu Lucid Lynx within VirtualBox) that wraps around several C/C++ binaries feeding the inputs of one into the others. One of the lines consists of generally: my $ret_code=`cat $input | c_binary`; my $ret_val= $?; For some input files the code causes a coredump, but both $ret_val and $ret_code are...

Operator overloading in C

I am trying to overload some operators: /* Typedef is required for operators */ typedef int Colour; /* Operators */ Colour operator+(Colour colour1, Colour colour2); Colour operator-(Colour colour1, Colour colour2); Colour operator*(Colour colour1, Colour colour2); Colour operator/(Colour colour1, Colour colour2); I get this error fo...

Syntax error, unexpected TRUE, expecting '{'

I'm writing a parser in Bison for a basic compiler (and then expand it to contain subroutines and dynamic memory allocation). The grammar is defined in Appendix A of the dragon book. My Flex scanner works--I ran my test files through it and it printed out all the correct tokens it found. Sorry about the strange formatting below. My bison...

Unknown return type for a C function.

I am writing a library for C, and one function can return either a string (char *), an integer or a double. Next to that, the length of the string is unknown. I really don't know how to deal with this problem. I thought about using pointers as arguments to the function but that is really messy. Can anyone give me a solution, and maybe s...

QrCode C/C++ API For Windows

Hi, I have looked after, without luck, a free C/C++ API for Windows that can be used in a project I am about to start. There are libraries for Java and C# but the fact is there is no one for C/C++. I need an API that can be integrated in a vs project and we cannot use libraries that run in servers ( as CGI scripts or whatever ). Does any...

What is the best way to supress "Unused variable x"-warning

What is the best/neatest way to suppress a compiler (in this case gcc) like "Unused variable x"-warning? I don't want to give any certain flags to gcc to remove all these warnings, just for special cases. ...

Assigning character pointer to a character pointer array.

Hi.. In this below code I wan to copy the string in 'pre' to array 'word' so that I can print the array 'word' later but it's showing NONPORTABLE CONVERSION error.. Tried doing it using strcpy() but it dint work. Any other way of doing it??I want to store the strings present in 'pre' into an array each time it's generated.. void print(c...

A Good Book About the C Programming Language

Possible Duplicates: Best book to learn C from the beginning? The Definitive C Book Guide and List (Surely this has been asked here before? But I cannot find any question...) I am an experienced Delphi programmer, but would like to learn C and C++ (good and fun to know, even if I will stick to Delphi). I know what C++ books...

Weird mod behavior in Obj. C

I have the following code: NSInteger index1 = (stop.timeIndex - 1); //This will be -1 index1 = index1 % [stop.schedule count]; // [stop.schedule count] = 33 So I have the expression -1 % 33. This should give me 32, but is instead giving me 3... I've double checked the values in the debugger. Does anyone have any ideas? ...

Serialize double and float with C

How can I serialize doubles and floats in C? I have the following code for serializing shorts, ints, and chars. unsigned char * serialize_char(unsigned char *buffer, char value) { buffer[0] = value; return buffer + 1; } unsigned char * serialize_int(unsigned char *buffer, int value) { buffer[0] = value >> 24; buffer[1]...

Opening win-socket (tcp) in kernel mode specifying sequence number

Hi, I'm writing a windows driver (of course in c and I'm in kernel mode) and I'd like to open a tcp socket from the outside specifying the sequence number the first SYN packet should have. I tried modifying the packet filtering it with Windows Filtering Platform, but of course it doesn't work because the stack think that the correct num...

Better way to declare this huge struct?

I am creating an application which uses a vCard struct. Currently, this struct looks like this: typedef struct { char *version; char **names; char *formatted_name; char *nickname; char *organisation; char *title; struct { /* Emails */ char *global_ty...

union consisting of float : completely insane output

#include <stdio.h> union NumericType { float value; int intvalue; }Values; int main() { Values.value = 1094795585.00; printf("%f \n",Values.value); return 0; } This program outputs as : 1094795648.000000 Can anybody explain Why is this happening? Why did the value of the float Values.value increase? Or am I m...

c binary file reading problems

hi i am reading a binary file using c as shown here link text so that all the information read from binary file is stored in "char *buffer". i have the format standard where it says that one of the lines should be format: unsigned char, size: 1 byte i am doing the following: printf("%x\n", buffer[N]); but what should i do ...

byte array to a short

Hello, I have an integer val. data[0]=0; data[1]=0; data[2]=(val>>8)%256; data[3]=val%256; How do I do the oposite? How do I take the int from the char array? ...

C Preprocessor, Stringify the result of a macro

Hi, I want to stringify the result of a macro expansion. I've tried with the following: #define QUOTE(str) #str #define TEST thisisatest #define TESTE QUOTE(TEST) And TESTE gets expanded to: "TEST", while I'm trying to get "thisisatest". I know this is the correct behavior of the preprocessor but can anyone help me with a way to ac...