structs

Assigning an address to a struct pointer array member in C.

Having considerable trouble with some pointer arithmatic. I think I get the concepts (pointer variables point to a memory address, normal variables point to data) but I believe my problem is with the syntax (*, &, (*), *(), etc.) What I want to do is build dynamic arrays of a custom struct (i.e. arrays of pointers to heap structs), and ...

Implementing a FIFO queue in C (not C++ nor C#)

For an embedded application, I am trying to implement a first-in, first-out (FIFO) queue of structs using ANSI C. The most straightforward way to do this seems to be by implementing a linked-list, so that each structure contains a pointer to the next in the queue. Hence I define the struct itself as: typedef enum { LED_on, LED_off, etc ...

C (beginner) : Why won't my qsort work? EDIT: From one error to another

I'm doing K&R exercise 6-4, which is: 6-4. Write a program that prints the distinct words in its input sorted into decreasing order of frequency of occurrence. Precede each word by its count. What I decided to do is create a struct called dstncFreqNode6_4: struct dstncFreqNode6_4 { char *word; int count; struct dstncFreqN...

Use C structs only and stay OOPy?

Say you have: struct c_struct { int value; /* other stuff */ void (* dump)(); }; and you'd like to, at some point: c_struct_obj->dump(); I assume there's no way you could instantiate a c_struct object such that its particular "dump" function knows its particular "value" the way C++ methods know member variables (via the im...

How do you directly type cast a boxed struct in C#?

I have a namespace of structs which represent various units of measure (Meters, Feet, Inches, etc.) ... anout 12 in total, generated courtesy of T4 templates :) . Each struct carries implicit casting operators to support casting the value to any other measurement value-type, so the following sytax is legal: var oneThousandMeters = new ...

C Program terminating with -1 (0xFFFFFFFF), seemingly no reason?

#include <stdio.h> typedef struct pduct {char name[20]; int price; int stock;} PRODUCT; void init(PRODUCT * product) { printf("What is the name of the product: "); fgets(product->name, 20, stdin); printf("DEBUG: Did it get written...: %s", product->name); printf("What is th...

Should I use a Struct?

Possible Duplicate: When to use struct in C#? Hi, I am creating an application that has a class in C# that is purely for holding variables, it does nothing else but set and get these variables. I was wondering, for efficiency and good coding practice, if I should convert this class to a struct so that it is being used properly...