paxdiablo gave the previous answer for it working with char array.. can I know how to work with int array for the same below code?
LIke:
struct encode {
int code[MAX]; //instead char code[MAX]
} a[10];
int main() {
int i, j;
int x[] = {3,0,2,5,9,3,1};
//instead char x[] = {'3','0','2','5','9','3','1','\0'};
for(i ...
Hey,
I have a a struct defined thusly:
typedef struct _CONFIGURATION_DATA {
BYTE configurationIndicator;
ULONG32 baudRate;
BYTE stopBits;
BYTE parity;
BYTE wordLength;
BYTE flowControl;
BYTE padding;
} CONFIGURATION_DATA;
Now, by my reckoning, that struct is 10 bytes long. However, sizeof reports that it ...
I am trying to create a symbol table using an array of an array of structs.
Right now I just have an array of structs and it's created like this:
#define MAXSIZE 20 /* maximum number of symbols */
#define MAXSCOPE 10 /* maximum number of scope levels */
struct tableEntry {
char *name;
char *args;
int value;
int scope;
char *type...
I have an array of structs. It's declared like this:
tableEntry [MAXSCOPE][MAXSIZE];
When the structs are created, C automatically initializes all the members to either 0 or null.
Let's say that I have given some values to the struct members of tableEntry[1][0], tableEntry[1][1], and tableEntry[1][2].
Now I want to reinitialize a...
Here's some C++ code that just looks funny to me, but I know it works.
There is a struct defined, and in the program we allocate memory using a void pointer. Then the struct is created using the allocated buffer.
Here's some code
typedef struct{
char buffer[1024];
} MyStruct
int main()
{
MyStruct* mystruct_ptr = 0;
void* ...
Hi,
We have seen lots of discussion in SO regarding the class vs struct in c#. Mostly ended with conclusions saying its a heap/stack memory allocation. And recommending to use structs in small data structures.
Now I have a situation to decide the simple data store among these two choices. Currenlty in our application we have thousands ...
Hi
I'm a little confused about how to specify my grammar member's type. I want to declare prog and decls as ASTNode. I'm gonna use these members for adding to a list or etc. But yacc can't recognize them as an ASTNode and I get type errors.
Here my tIdent,tCharConst,tIntConstant have some types but, how to give ASTNode type to my membe...
I know something about struct type. But I can't understand: what is it for? when have I use it? Classes, simple value-types and enums - that's all that I need.
Any suggestions?
UPD: PLEASE! Don't tell me that struct is in the stack (I know this :). What struct is for?
...
I can do this in c++/g++:
struct vec3 {
union {
struct {
float x, y, z;
};
float xyz[3];
};
};
Then,
vec3 v;
assert(&v.xyz[0] == &v.x);
assert(&v.xyz[1] == &v.y);
assert(&v.xyz[2] == &v.z);
will work.
How does one do this in c with gcc? I have
typedef struct {
union {
st...
I've defined a struct and want to assign one of its values to a NSMutableDictionary. When I try, I get a EXC_BAD_ACCESS. Here is the code:
//in .h file
typedef struct {
NSString *valueOne;
NSString *valueTwo;
} myStruct;
myStruct aStruct;
//in .m file
- (void)viewDidLoad {
[super viewDidLoad];
aStruct.valueOne = @"firstValue";
}
/...
In C#, any user-defined struct is automatically a subclass of System.Struct and System.Struct is a subclass of System.Object.
But when we assign some struct to object-type reference it gets boxed.
e.g.
struct A{
public int i;
}
A a;
object obj=a; // boxing takes place here
So my question is - if A is an descendant of System.Obj...
struct SomeStruct
{
public int Num { get; set; }
}
class Program
{
static Action action;
static void Foo()
{
SomeStruct someStruct = new SomeStruct { Num = 5 };
action = () => Console.WriteLine(someStruct.Num);
}
static void Main()
{
Foo();
action.Invoke();
}
}
Is a co...
I'm testing out NHibernate to be the solution to my company's ORM needs. To do this, I've produced a small test model based on a school, providing some useful edge-cases for NHibernate to handle.
I'm having problems finding out how to map a custom structure as a component of an entity without using theIUserType interface. I should stres...
i basically want to take int name and string age from user in c# and send it to dll method written in c which take int and char[50] arguments in it and return string .i created following scenario but i am failed ,any body has the code
i have a dll developed in c which ahas a structure
struct Argument
{
int age;
char name[50];
} ;
...
I have a C++ struct that looks like this:
struct unmanagedstruct
{
int flags;
union
{
int offset[6];
struct
{
float pos[3];
float q[4];
} posedesc;
} u;
};
And I'm trying to Marshal it like so in C#:
[StructLayout(Layou...
Let's say that you were to have a structure similar to the following:
struct Person {
int gender; // betwwen 0-1
int age; // between 0-200
int birthmonth; // between 0-11
int birthday; // between 1-31
int birthdayofweek; // between 0-6
}
In terms of performance, which would be the best data ...
My code is as follows:
#include <stdio.h>
struct MyData {
int id;
char msg[255];
};
int main ( int argc, const char * argv[] ) {
struct MyData item;
item.id = 3;
item.msg = "something else";
printf("Msg: %d", item.msg);
return 0;
}
I get an error of incompatible types in assignment on the line:
item.msg ...
How do you add a record if you send as a parameter to a function?
struct record {
char name[20];
int nr;
};
void AddRecord(struct record **p_allRecs, int p_size);
int main() {
struct record *allRecs;
/* putting in some records manually, size++... */
allRecs = (struct record *)malloc(size*sizeof(struct record));
}
AddRecord(&allRecs,...
In Win32 API programming it's typical to use C structs with multiple fields. Usually only a couple of them have meaningful values and all others have to be zeroed out. This can be achieved in either of the two ways:
STRUCT theStruct;
memset( &theStruct, 0, sizeof( STRUCT ) );
or
STRUCT theStruct = {};
The second variant looks clean...
Suppose I have a struct containing a std::string, like this:
struct userdata{
int uid;
std::string username;
}
Do I need to create a copy ctor or anything to return it from a function or to use it inside a STL container? Consider this function:
userdata SomeClass::GetUserData(unsigned int uid)
{
//do error che...