problem about structures-Collection of common programming errors


  • Potatoswatter
    c++ nested structures unions
    I had a need to declare a union inside a structure as defined below:struct MyStruct {int m_DataType;DWORD m_DataLen;union theData{char m_Buff [_MAX_PATH];struct MyData m_myData;} m_Data; };Initially, I tried accessing the union data as follows (before I added the m_Data declaration):MyStruct m_myStruct;char* pBuff = m_myStruct.theData::m_Buff;This compiles but returns to pBuff a pointer to the beginning of the MyStruct structure which caused me to overwrite the m_DataType & m_DataLen

  • DeadMG
    c++ data allocation structures
    I asked a similar question before, but I only realized now that the answer I received isn’t totally what I wanted.If I simply have a pointer of some structure type, how can I either move to, or create an instance of the same structure type starting at an address specified by the struct pointer (which I have assigned an address to) without using “new”.

  • Jason
    java data big-o structures
    Question pretty much says it all. Specifically, I would like the Big-O of all the methods within a structure, aside from the usual. The docs say very little about this.AddennumFor those who are voting to close, I am not interested in the basic add, remove, iterator, etc Those sources are fine for regularly used methods, but I am more interested in the algorithmic efficiency of the rest of the pile.For example, what is the efficiency of TreeMap.keySet()?

  • codaddict
    c memory malloc structures
    I asked a question earlier on defining a structure using malloc. This was the answer I was given by the majority:struct retValue* st = malloc(sizeof(*st));I was showing a friend my code, and we came to a stumbling block. Could someone please explain why this code works? From my viewpoint, *st hasn’t been defined when you malloc it, so there could be any kind of garbage in there. It should be malloc(sizeof(struct retValue)) Thanks for any help

  • Rvd
    python ctypes structures
    Using ctypes I have defined the following class:class ListOfVariables(Structure):_fields_ = [(“name0”, c_int),(“name1”, c_int),(“name2”, c_int) ] Is it possible the add one element to the member ‘fields’ at runtime? So that we can define a new variable in the following manner, for example:cstructA = ListOfVariables(1,2,3,4)or even with another type:cstructB = ListOfVariables(1,2,3,’b’)It is a necessity that after modifying the class dynamically the constructor is

  • Andrew Barber
    c++ arrays heap structures
    I need to declare an array of structures on the heap, then transfer data from parallel arrays on the stack and from calculations into each structure. I declared struct Grades {string studentName;int scores[4];double average; };….Grades *art1301 = new Grades;….(art1301 + i)->studentName = names[i];for((int i = 0 ; i < 5 ; i++ ) (art1301 + i)->scores[j] = exams[i][j];(art1301 + i)->average = average; My program accesses the first record, but it crashes after it accesses the f

  • Jeroen Moons
    c pointers segmentation-fault structures
    I just got started on a lab of mine where I calculate the GPA of courses whose information is stored in a linked list of structures. As of now, I’m attempting to just print out all the course information to ensure that they have been properly initialized and added to the link list. I’m running into a problem though because I keep getting a Segmentation Fault. I understand what the Segmentation Fault means, but I do not know where I am making my mistake. Any help would be appreciated. #include &l

  • iymz
    c++ arrays structures
    I have one arrays of structures with few elements. I want dynamic increasing array. I created second structures – temporary – and I allocate for double size. Then I copy all record from first structures and delete it. But it is problem and program report segfault.Student ** pom_student;pom_student = new Student*[counter*MULTIPLY];for(int i=0;i<counter*MULTIPLY;i++) {pom_student[i] = new Student[counter*MULTIPLY];}for(int i=0;i<counter;i++) {pom_student[i]->name = student[i]->name;pom

  • John Kugelman
    python pointers ctypes structures
    I have to access a POS terminal under ms windows xp. I am using python 2.7. The crucial function in the DLL I load that does the payment accepts two pointer to structures, but it crashes returning 1 (Communication error) but without further messages. Please note that when the payment function is called, not all the elements of POSData structure receive a value. Other function I tried (GetVersion) does work. Here specifications and my code:typedef struct {char IPAddress[16]; //xxx.xxx.xxx.xxxint

  • razlebe
    vb.net arrays file-io structures
    I have 2 StructuresPublic Structure One Public ItemOne As StringPublic ItemTwo As IntegerEnd StructurePublic Structure Two Public ItemOne As StringPublic ItemTwo As IntegerPublic ItemThree As IntegerPublic ItemFour As IntegerPublic ItemFive As IntegerEnd StructurePublic TestOne(0) as One Public TestTwo(19) as TwoUsing the FileOpen, FilePut and FileClose method, I get an error: (Stripped down to only related code as an example)Public Sub WriteOne()FileOpen(1,

  • pighead10
    c++ exception structures unhandled
    The program throws an unhandled exception on this line:}else if(s == “backpack”){cout << “\nEquipped items: ” << endl;cout << weapon->Name << endl << cArmour->Name << endl; //this lineIt prints ‘Equipped items: ‘ then throws an exception. This file – Player.h – includes Library.h, which in turn includes Globals.h, which has the structs:struct sWeapon{std::string Name;int Damage; };struct sArmour{std::string Name;int AP; };In the Player constructor, it cr

  • luser droog
    c structures fgets sscanf
    I am attempting to read saved data from a file. I am trying to convert the information in the buffer from a string to characters and assign their values to the members of the structure. It seems the data is not being accessed correctly,when I print out the node values, it is different from what is sored in the file. I cant see where I am going wrong. The file format: 3 2 43 4 2 4 5 6$Node41 0 -1 02 0 1 0 3 10 -1 04 10 1 0$EndNodes$Elements21 2 3 4 2 3 5 6$EndElementsThe code: struct Node {int x

  • icelated
    c++ data structures
    I have a program thats using adt / abstract data classes with data structures. Object -> Ownership-> container -> stack -> queue -> queueslinkedlist , etc.. I switched to code blocks from visual studio because i was having ostream issues..I commented out some functions in order to track down issues..I am trying to get it to compile. In the queueaslinklist.h file is where i am having problems.class QueueAsLinkedList : public virtual Queue { protected: LinkedList<Object*> list;When i commen

  • Anonymous
    c pointers structures
    I have a few structures with cross-pointers in my program, they are defined like this:typedef struct {…struct myvar *next;struct myvar *prev;… } myvar;typedef struct {…myvar *first;… } variables;And I am getting a strange error on the next piece of code:variables *Variables; … Variables->first->prev->next = Variables->first;I am using MS Visual Studio, and it sayserror C2037: left of ‘next’ specifies undefined struct/union ‘myvar’I have set it to Compile as C Code (/TC), in

  • Rainer Joswig
    common-lisp structures accessor clos ccl
    In common lisp, what can I use to access structure slot using slot name/symbol?What I want is(defstruct point (x 0) (y 0)) (defmacro -> (struct slot) `(slot-value ,struct ,slot))(setf p (make-point)) (setf (slot-value p ‘x) 1) (setf (-> p ‘y) 2)I’m using clozure cl, and In clozure cl this works. However, AFAIK this is non-standard behavior (equivalent to “undefined behavior” C++). I’m not planning to switch to another CL implementation, so should I keep using slot-value for structures

  • GilgameshOfUruk
    c++ visual-studio-2010 header source structures
    I have a header, and it includes a prototype of a structure:struct UserDataStruct;The source file for the header contains and include for the header and:struct UserDataStruct {int instance; };In my main source file, I have:int main () {UserDataStruct lol;return 0; }I can’t seem to compile my program because Visual Studio 2010 gives me an error:error C2079: ‘lol’ uses undefined struct ‘UserDataStruct’How can I make this work?

  • Ben313
    c++ structures
    I have a structure Defined in the Header file for a class i am working in, and i am trying to use the Struct in one of the methods of the class. It looks basically like this:struct example {double a;int b;… };in the header above my class definition, and then in the cpp file, i have:void exampleclass::test(){struct example *teststruct;teststruct->a = 0; //This line causes a access violation}why do i get an error here? Im sure im doing something clompletly wrong here, and i must say im a huge

  • Stanley
    coldfusion structures
    <cfparam name=”airInfo.leaving” type=”struct” default=”#structNew()#”> <cfparam name=”flightInfo.depart” type=”string” default=”departing”> <cfparam name=”flightInfo.arrive” type=”string” default=”arriving”><cfset flightInfo = airInfo.leaving> <cfset fromInfo = flightInfo.depart> <cfset arriveInfo = flightInfo.arrive><cfdump var=”#flightInfo#”>This should work… I think, but I keep getting an error saying depart is undefined in flightInf

  • Alex
    c pointers static structures
    struct x {int *u; };struct y {struct x *z; };int main() {static y b;static int g=7;b.z->u=&g; }The statement b.z->u=&g gives a segmentation error. If I remove the static in front of int g:int g=7; b.z->u=&g; The code executes properly.

  • David Morris
    c arrays pointers structures
    I am attempting to tackle college worksheet on C programming (no marking for it, just to improve our learning). What we’re meant to do is get a few details about shipping docks. I decided to use structures for this.My code is below, what I need help with is to print out the information (to see if its working) of whats at the location of the shipyards .run.Everything compiles and according to the debugger shipyard1.run and shipyard2.run point to different locations, but I can not see the values.i

  • caf
    c++ class structures forward-declaration
    int main() {B bb; //does not compile (neither does class B bb;)C cc; //does not compilestruct t tt; //compilesclass B {}; //HERE is the class B definationstruct s { struct t * pt; }; //compilesstruct t { struct s * ps; };return 0; }class C {};I just modified the example given here.Why is that the struct forward declarations work but not the class forward declarations?Does it have something to do with th

  • Shail
    c pointers syntax structures
    I was writing a program for finding the addition, multiplication and division of two rational numbers using a structure and pointers. I am having a problem inputting the numbers with pointers. How should my code be corrected? Thanks!#include <stdio.h> struct rational {int nu;int de; }*p1,*p2,*p3; void add() {p1->nu = p1->nu*p2->de + p1->de*p2->nu;p3->de = p1->de * p2->de;printf(“%d\n–\n%d\n”,p3->nu,p3->de); } void multiply() {p3->nu = p1->nu * p2->nu

  • attaboy182
    c pointers structures
    Could anyone please tell me how “hello” is being printed here? As far as my knowledge goes, local variables are uninitialized. Therefore, I thought the else part should be printed but it’s happening otherwise. Please help.struct buss{ int a; char b; };void main(){struct buss *p;if(p==NULL) printf(“hello”);else printf(“hi”);}

  • user2226030
    arrays function reference undefined structures
    Hi this is my first time posting here, and I am relatively new to coding so I am having a lot of problems with it. Most of the time I can learn it on my own on on how to fix error, but now I think I just hit a major road block with arrays and structures. At the moment, when compiling it will give meundefined reference to `buildArrays(std::string, int, int, int)’The problem is, I keep having this error every time I try to “fix” the buildArray caller in the main function, changing the string PlaNa

  • simar
    c extern structures
    I’m trying to implement tree algorithms in C. I have declared a extern struct in a header file that is completely independent (b_tree_ds.h). Now I plan to import the file in all source files that want to use this struct. So I must declare it using extern in header.Now the problem is thhat I want to define its typedef as well. the compiler gives error of multiple storage classes. How should I do that.typedef extern struct node {struct node* left;struct node* right;int key; // contains value }N

  • Suhail Gupta
    c linux gcc compiler-errors structures
    In the following program I try to pass a structure to a function. But I get errors,and I do not understand why. What mistake have I made in this program ?I am using gcc for compiling this c program.#include <stdio.h>struct tester {int x;int *ptr; };void function(tester t);int main() {tester t;t.x = 10;t.ptr = & t.x;function(t); }void function(tester t) {printf(“%d\n%p\n”,t.x,t.ptr); }Errors :gcc tester.c -o testertester.c:8:15: error: unknown type name ‘tester’ tester.c: In function ‘m

Web site is in building