c

C Pointer confusion

Hi! I want to store a string in memory and read it later: $$->desc.constant->base.id = (char*)malloc(200); sprintf($$->desc.constant->base.id, "%f", $1); printf("->%s\n", $$->desc.constant->base.id); //LINE A printf("->%i\n", $$->desc.constant); //LINE B //SOME OTHER CODE //Then, later on in a function call: printf("%i", expr->desc...

Difference between a Structure and a Union in C

Is there any good example to give the difference between a 'struct' and a 'union'? Basically I know that struct uses all the memory of its member and union uses the largest members memory space. Is there any other OS level difference? ...

How to work with pointer to pointer to structure in C?

Hi, I want to change member of structure under double pointer. Do you know how? Example code typedef struct { int member; } Ttype; void changeMember(Ttype **foo) { //I don`t know how to do it //maybe *foo->member = 1; } Thanks for any help. ...

How do spell checkers work?

I need to implement a spell checker in C. Basically, I need all the standard operations... I need to be able to spell check a block of text, make word suggestions and dynamically add new words to the index. I'd kind of like to write this myself, tho I really don't know where to begin. ...

Accessing a bidimensional(or tridimensional) array through a pointer

When you have an array like this: int foo[3][2][2]; and you make: int *bar = &foo[0][0][0]; Is this the way it works? *bar == foo[0][0][0]; *(bar+1) == foo[0][0][1]; *(bar+2) == foo[0][1][0]; *(bar+3) == foo[0][1][1]; *(bar+4) == foo[1][0][0]; I'm not sure and have a bit of code dependent on if that works. ...

Determining the TCP port number to which client got bound.

Hi, I create a TCP socket without bothering about the port number to bind to [socket.sin_port = 0]. However later on if I want to print the port number of client how do I do that? The client C application (on Linux) creates many clients which get connected to server. To debug issues I capture the traffic on ethereal. I thought of printi...

How to use embedded c within Shoes? (ruby-serialport)

Is it possible to use something like: require 'serialport.o' with Shoes? serialport.o is compiled c code as a ruby extension. When I attempt to run the following code in shoes, I see no visible output to the screen and shoes crashes on OS X. Thank you CODE: require "serialport.o" port = "/dev/tty.usbserial-A1001O0o" sp = Serial...

What does 1.#INF00, -1.#IND00 and -1.#IND means?

I'm messing around with some C code using floats and I'm getting 1.#INF00, -1.#IND00 and -1.#IND when I try to print floats in the screen. What does those values mean? I believe that 1.#INF00 means positive infinity, but what about -1.#IND00 and -1.#IND? I also saw sometimes this value: 1.$NaN which is Not a Number but what causes those ...

How do you deal with discrete sets of non integer numbers?

I have a program that needs to do a *compile time checkable** map from one known set of values to another known set of values: in out ------------ 8 37 10 61 12 92 13 1/4 109 15 1/4 151 etc This would be easy if the inputs were either integers or evenly spaced. I'm going to be iterating over the rows but also w...

Domain Specific Language in C/C++, does this Kosher?

I was just fooling around with some Domain Specific Language designs for a new project in C/C++ when I thought up this "odd" solution: define DSL(...) MakeCommand(#__VA_ARGS__\ )->Exec()->GetResults() MyResults results = DSL( for p in people do something ); The nice part is this is correct by the stand...

Is TCP Keepalive the only mechanism to determine a broken link?

I recently ran into a issue where intermediate link betweeen a TCP server and client was down. The client has the requirement of connecting to a secondary server if the primary server is down. When the primary server is bought down (Ex ..by doing ^C on the terminal), there is TCP shutdown sequence that gets through and client sucessfully...

How do I print one bit?

Please tell me how do I print a bit, like printf("%d",bit); Thanks a lot ...

Why is my Python C Extension leaking memory?

The function below takes a python file handle, reads in packed binary data from the file, creates a Python dictionary and returns it. If I loop it endlessly, it'll continually consume RAM. What's wrong with my RefCounting? static PyObject* __binParse_getDBHeader(PyObject *self, PyObject *args){ PyObject *o; //generic object PyObject*...

printf("something\n") outputs "something " (additional space) (g++/linux/reading output file with gedit)

I have a simple C++ program that reads stdin using scanf and returns results to stdout using printf: #include <iostream> using namespace std; int main() { int n, x; int f=0, s=0, t=0; scanf("%d", scanf("%d", for(int index=0; index<n; index++) { scanf("%d", scanf("%d", scanf("%d", ...

How do you put a breakpoint on a memory location in dbx?

A co-worker has a C program that fails in a predictable manner because of some corrupted memory. He'd like to use dbx to monitor the memory location once it's allocated in order to pinpoint the code that causes the corruption. Is this possible? If so what is the syntax to produce a breakpoint at the moment of corruption? If not, what...

How to get function's name from function's pointer in C?

How to get function's name from function's pointer in C? Edit: The real case is: I'm writing a linux kernel module and I'm calling kernel functions. Some of these functions are pointers and I want to inspect the code of that function in the kernel source. But I don't know which function it is pointing to. I thought it could be done beca...

How do I accept an md5sum via command line in C?

typedef union { uint ui[4]; } md5hash; void main(void) { int opt; while ((opt = getopt(argc, argv, "c:t:s:h:")) != -1) { switch (opt) { case 'h': hash = optarg; break; default: /* '?' */ exit(EXIT_FAILURE); } } md5hash hash; sscanf(hash, "%x%x...

Can you write object oriented code in C?

Can you write object oriented code in C? Especially with regard to polymorphism. See also: http://stackoverflow.com/questions/415452/object-orientation-in-c ...

Where is the Don't Fragment Bit of the IP Flags used?

I am curious to know where the "Don't Fragment" [DF] Bit of the IP Flags is used. As fragmentation is invisible to higher layers and they don't care too. I am also looking for an example. Thanks a lot in advance. ...

ANSI C: Assigning arrays and pointers to arrays

The following is a simplified version of what I'm trying to do, because I'm sure you don't want to wade through an entire set of structs and function prototypes for a particle system. float const materials[24][4][4] = {{{...}}}; typedef struct EmitterStruct { float *material[4][4]; } Emitter; typedef struct ParticleStruct { float mater...