I am using a struct and I want to initialize a maximum of 10 ports. However, when the program is running it could be a lot less, we don't know until ... |
I write a 'constructor' function that makes a Node in C, compiled with Visual Studio 2008, ANSI C mode.
#include <stdio.h>
#include <stdlib.h>
typedef struct _node
{
struct _node* next ;
char* data ...
|
gcc c89
I am getting a stack dump on this line:
strcpy(comp->persons->name, "Joe");
However, I have allocated memory, so not sure why I would be getting it. Am I missing something here?
Many thanks for ... |
Hi here is my code. I want to dynamincly change no of elemnts in table with structs __state:
typedef struct __state{
long int timestamp;
int val;
...
|
Can someone please explain me this peculiar output:
#include <stdio.h>
typedef struct node
{
int i;
struct node *next;
}node;
main()
{
node *p,*q;
printf(" %u ",sizeof(node)); ...
|
Possible Duplicate:
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
#include <stdio.h>
int main(){
struct word1{
char a;
int b;
char ...
|
If I were to define a statically allocated struct in place, I'd do:
struct mystructure x = {3, 'a', 0.3};
Is there a way I can do the same in C but using ... |
|
I have a packet from a server which is parsed in an embedded system. I need to parse it in a very efficient way, avoiding memory issues, like overlapping, corrupting my ... |
consider the following code:-
struct mystruct {
int data;
struct mystruct *next;
};
void myfunc ()
{
struct mystruct s1;
s1.data= 0;
s1.next = NULL;
myfunc2(&s1);
..
..
}
is it ... |
I've dynamically allocated a structure, conceptually very similar to a matrix, to hold a set of strings. I've encountered a problem while trying to free the memory. My code looks like ... |
Why is not 12 in the first case?
Tested on: latest versions of gcc and clang, 64bit Linux
struct desc
{
int** parts;
int nr;
};
sizeof(desc); Output: 16
struct desc
{
...
|
Assuming we have a simple struct like:
typedef struct
{
int d1;
int d2;
float f1;
}Type;
Which is the correct when allocate memory for a ... |
Line 17, you allocate memory for f[0].name but not for the name pointer in the other 49 structures in the array you allocated at line 16. Also it is normally good practice to give your variables meaningful names except for loop counters (and some would say not even then) variable names should be > 3 characters long. |
P: n/a Andrew Smallshaw I'm working on a data structure that began life as a skip list derivative, but has evolved to the point that it now only has a passing resemblance to them. Each node of this structure has a few constant size variables (ints and the like), an array holding the actual data (chars in this case) and a ... |
Hello; I have 2 questions: 1- I know you can allocate memory to an array dinamically in C and C++. But, can this be done if the array is part of a structure? 2- Can the size of a dynamic array automatically grow up to a maximum or do you have to increase it when needed yourself? This is my exact ... |
How is the memory allocated for structures? I need to optimize the memory usage and bit fields are not doing the trick. Any details about the memory allocation for the structures would be a great help. PS - I already have asked this in gcc group. Please refrain from directing me towards other groups. |
bharath539@gmail.com wrote: how much memory is allocated for following structure struct bharath { int b; char c; float d; } > and how? > Enough to fit at least the total memory requirements of the struct. Since the primitive types in the struct can vary in width from platform to platform and implementation to implementation (except char, of course) the size ... |
P: n/a Yourko Hello! I ame working on a hobby-project - a simple TCP/IP server. Its purpose (for now) is to act like a chat program: send all received data from one connected client to all others. First step is to listen on port: void server_init(void){ int main_socket; main_socket = create_socket(port); /* Two filedescriptor sets for use with select() */ fd_set ... |
problem with memory allocation and structs Hello I am working on a program that requires me to use structs. I am allocating memory for the struct and the variables defined in them. I am sure there is something incorrect with my code because there is undefined behavior when running the program. I am posting the code so if any of you ... |
|
Piggybacking on old threads is generally considered bad form around here. Next time, if there's no active thread, start a new one. Also use code tags when posting source code. A lot of people won't read it if you don't. Your code seems unnecessarily complex... For one thing I don't understand why you're using the rather complex (*Struct).Element notation when it's ... |
So 0xfffffff9 is, what, -7? Somehow along the way, the pointer you malloc and the pointer you try to free are not the same. I don't know enough about GTK to know what the parameters to pass in to a destroy handler are supposed to be. (EDIT: My point there, which I appear to have forgotten to mention, is that if ... |
Hi, I'm quite inexperienced as far as C programming goes and I have some problems regarding memory allocation. Those are the relevant code segments: Code: typedef struct allowedEdge_t { int e; unsigned char res; struct allowedEdge_t *left; struct allowedEdge_t *right; } allowedEdge; typedef struct node_t { int edgeCount1; int* edges1; int arLength1; int edgeCount2; int* edges2; int arLength2; int psi; int ... |
Code: #include /* sanddune's declarations */ int main() { rsp *with_two = malloc(sizeof(rsp) + 2 * sizeof(statusrecord)); if (with_two != NULL) { /* effectively with_two points at an rsp object that has two statusrecords */ with_two->stRec[0].a = 5; /* OK as we have two statusrecords */ with_two->stRec[0].ch = 'A'; /* OK as we have two statusrecords */ with_two->stRec[1].a = 5; ... |
Help - Linked Lists/Structures/Memory Allocation Hello I'm having trouble getting my program to do what it needs because i don't completely understand how linked lists work. If i could get a some help i'd greatly appreciate it. I mainly need help with making it go through the 1,000 time steps, remove cars that have crashed, and debugging a few problems. Here's ... |
|
(Dev-C++ in Windows Vista / GCC in Ubuntu) My goal is to eventually read line by line from a file that contains combined lengths of text like those joined into the "input" variable. Currently, the code below crashes the console in windows and in linux it points to a "realloc(): invalid next size" error. I realize that most of this code ... |
|
I'm trying to get a program working that has a very large structure group. The structure is of the form: Code: typedef struct { double x; double y; double z; } Vect; typedef struct { Vect vector1; Vect vector2; Vect vector3; //(6 doubles); } Param1; typedef struct { //(3 doubles); //(8 integers); } Param2; typedef struct { Param2 param2[256]; double P3d[17]; ... |
|
|
#include #include typedef struct { int some_data; } LIST; int main(void) { LIST* item; LIST* item2; item = malloc(sizeof(LIST)); item->some_data = 33; printf("some_data = %d\n", item->some_data); free(item); item2 = malloc(sizeof(*item2)); item2->some_data = 42; printf("some_data = %d\n", item->some_data); // should I still be able to access this after the free? return 0; } |
|
|
|
|
Hi All, while reading a book on TCP/IP i recently came across a piece of code that read.... #include #include #include typedef struct { int a; char data[1]; }TCB; int main() { TCB *tp; .... ..... tp=(TCB *) malloc(sizeof(TCB)); .... .... strcpy(tp->data,"ABCDEFGH"); .... ... } I wonder how you can assign string like this to a 1 byte long ... |
|
|
Thanks for the timely reply I tried your suggestion and I am now getting quite a few compiler errors in the statements where I reference the structure rf_move_struct_p[i-y].move_status = MR$_NO_LOAD; .................^ %CC-E-NEEDPOINTER, In this statement, "rf_move_struct_p" has a signed int type, but occurs in a context that requires a pointer. at line number 4364 in file _______________________________ Here's a synopsis of ... |
struct rec *p; (*p).i=10; You have absolutely no idea where you just tried to write that integer - usually somewhere unpleasant, which is why the OS steps in with a seg fault. If you're unfortunate, it will work, thus suckering you into thinking your program is correct, when in fact it isn't. struct rec *p; p=(struct rec *) malloc (sizeof(struct rec)); ... |
|
hello folks!, m new to C and devshed. juss started off with the language. can anyone help me with the program int main() { struct book { char name; float price; int pages; }; book b1; b1.name='a'; b1.price=200; b1.pages=350; printf("%u %u %u",&b1.name,&b1.price,&b1.pages); } (please assume all the libraries are made available.) output of the following program is given as 2293568 2293572 ... |
Hello I'm having trouble getting my program to do what it needs because i don't completely understand how linked lists work. If i could get a some help i'd greatly appreciate it. I mainly need help with making it go through the 1,000 time steps, remove cars that have crashed, and debugging a few problems. Here's the question: Consider a square ... |
|
Hello, I am trying to allocate memory to a structure, then assign a string to one member of the structure. This is the code: Code: //definition of the hostent structure is in a header file struct hostent { /* structure for gethostbyname */ char *h_name; /* official name of host */ char **h_aliases; /* alias list */ int h_addrtype; /* host ... |
First of all, I think you're confusing the struct and union keywords. For a struct (or a union for that matter), it won't matter how you arrange the elements. The number of bytes allocated will still be the same, no matter how you arrange the elements. With that said, let's get to the difference between a union and a struct. The ... |
|
|
|
|
Thanks Narue; But my problem is that I can't predict how many paths a node will have. Even if I define paths as a pointer to type path_info, I will have to allocate a certain amount of memory to it which means it will be the same for every node. So, I will have to allocate the maximum possible number of ... |