Search Results

Search found 2566 results on 103 pages for 'struct'.

Page 14/103 | < Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >

  • scheme struct question

    - by qzar
    ;; definition of the structure "book" ;; author: string - the author of the book ;; title: string - the title of the book ;; genre: symbol - the genre (define-struct book (author title genre)) (define lotr1 (make-book "John R. R. Tolkien" "The Fellowship of the Ring" 'Fantasy)) (define glory (make-book "David Brin" "Glory Season" 'ScienceFiction)) (define firstFamily (make-book "David Baldacci" "First Family" 'Thriller)) (define some-books (list lotr1 glory firstFamily)) ;; count-books-for-genre: symbol (list of books) -> number ;; the procedure takes a symbol and a list of books and produces the number ;; of books from the given symbol and genre ;; example: (count-books-for-genre 'Fantasy some-books) should produce 1 (define (count-books-for-genre genre lob) (if (empty? lob) 0 (if (symbol=? (book-genre (first lob)) genre) (+ 1 (count-books-for-genre (rest lob) genre)) (count-books-for-genre (rest lob) genre) ) ) ) (count-books-for-genre 'Fantasy some-books) It produce following exception first: expected argument of type non-empty list; given 'Fantasy, I don't understand whats the problem. Can somebody give me some explanation ? Thank you very much !

    Read the article

  • Using std::ifstream to load in an array of struct data type into a std::vector

    - by Sent1nel
    I am working on a bitmap loader in C++ and when moving from the C style array to the std::vector I have run into an usual problem of which Google does not seem to have the answer. 8 Bit and 4 bit, bitmaps contain a colour palette. The colour palette has blue, green, red and reserved components each 1 byte in size. // Colour palette struct BGRQuad { UInt8 blue; UInt8 green; UInt8 red; UInt8 reserved; }; The problem I am having is when I create a vector of the BGRQuad structure I can no longer use the ifstream read function to load data from the file directly into the BGRQuad vector. // This code throws an assert failure! std::vecotr quads; if (coloursUsed) // colour table available { // read in the colours quads.reserve(coloursUsed); inFile.read( reinterpret_cast(&quads[0]), coloursUsed * sizeof(BGRQuad) ); } Does anyone know how to read directly into the vector without having to create a C array and copy data into the BGRQuad vector?

    Read the article

  • Pointer inside a struct / thread

    - by bruno
    Hi! I have this warning "warning: assignment from incompatible pointer type " in this line: data1->transformed_block[l] = &transformed_block[l]; - void print_message_function ( void *ptr ) { dt *data; data = (dt *) ptr; printf("Dentro da thread Numero0: %ld\n", data->L_norm_NewBlock); pthread_exit(0); } typedef struct data_thread { long L_norm_NewBlock; int Bsize_X; int Bsize_Y; int *transformed_block[MAX_LEVEL]; long L_norm_OrigBlock; } dt; void function() { int *transformed_block[MAX_LEVEL]; pthread_t thread1; dt *data1; pthread_attr_t attr; pthread_attr_init(&attr); //Fills structure data1 = (dt *) malloc(sizeof(dt)); data1->transformed_block[l] = &transformed_block[l]; data1->L_norm_NewBlock=0; data1->Bsize_Y = Bsize_Y; data1->Bsize_X = Bsize_X; pthread_create(&thread1, &attr, (void *) &print_message_function, (void *) &data1); } I want to get rid of that warning, and the values i get inside the thread are wrong. For example data1-L_norm_NewBlock=0; in the thread guives me a differente value (not 0 like it should be).

    Read the article

  • struct constructor + function parameter

    - by Oops
    Hi, I am a C++ beginner. I have the following code, the reult is not what I expect. The question is why, resp. what is wrong. For sure, the most of you see it at the first glance. struct Complex { float imag; float real; Complex( float i, float r) { imag = i; real = r; } Complex( float r) { Complex(0, r); } std::string str() { std::ostringstream s; s << "imag: " << imag << " | real: " << real << std::endl; return s.str(); } }; class Complexes { std::vector<Complex> * _complexes; public: Complexes(){ _complexes = new std::vector<Complex>; } void Add( Complex elem ) { _complexes->push_back( elem ); } std::string str( int index ) { std::ostringstream oss; Complex c = _complexes->at(index); oss << c.str(); return oss.str(); } }; int main(){ Complexes * cs = new Complexes(); //cs->Add(123.4f); cs->Add(Complex(123.4f)); std::cout << cs->str(0); return 0; } for now I am interested in the basics of c++ not in the complexnumber theory ;-) it would be nice if the "Add" function does also accept one real (without an extra overloading) instead of only a Complex-object is this possible? many thanks in advance Oops

    Read the article

  • Receiving "expected expression before" Error When Using A Struct

    - by Zach Dziura
    I'm in the process of creating a simple 2D game engine in C with a group of friends at school. I'd like to write this engine in an Object-Oriented way, using structs as classes, function pointers as methods, etc. To emulate standard OOP syntax, I created a create() function which allocates space in memory for the object. I'm in the process of testing it out, and I'm receiving an error. Here is my code for two files that I'm using to test: test.c: #include <stdio.h> int main() { typedef struct { int i; } Class; Class *test = (Class*) create(Class); test->i = 1; printf("The value of \"test\" is: %i\n", test->i); return 0; } utils.c: #include <stdio.h> #include <stdlib.h> #include "utils.h" void* create(const void* class) { void *obj = (void*) malloc(sizeof(class)); if (obj == 0) { printf("Error allocating memory.\n"); return (int*) -1; } else { return obj; } } void destroy(void* object) { free(object); } The utils.h file simply holds prototypes for the create() and destroy() functions. When I execute gcc test.c utils.c -o test, I'm receiving this error message: test.c: In function 'main': test.c:10:32: error: expected expression before 'Class' I know it has something to do with my typedef at the beginning, and how I'm probably not using proper syntax. But I have no idea what that proper syntax is. Can anyone help?

    Read the article

  • Access Violation Using memcpy or Assignment to an Array in a Struct

    - by Synetech inc.
    Hi, I wrote a program last night that worked just fine but when I refactored it today to make it more extensible, I ended up with a problem. The original version had a hard-coded array of bytes. After some processing, some bytes were written into the array and then some more processing was done. To avoid hard-coding the pattern, I put the array in a structure so that I could add some related data and create an array of them. However now, I cannot write to the array in the structure. Here’s a pseudo-code example: main() { char pattern[]="\x32\x33\x12\x13\xba\xbb"; PrintData(pattern); pattern[2]='\x65'; PrintData(pattern); } That one works but this one does not: struct ENTRY { char* pattern; int somenum; }; main() { ENTRY Entries[] = { {"\x32\x33\x12\x13\xba\xbb\x9a\xbc", 44} , {"\x12\x34\x56\x78", 555} }; PrintData(Entries[0].pattern); Entries[0].pattern[2]='\x65'; //0xC0000005 exception!!! :( PrintData(Entries[0].pattern); } The second version causes an access violation exception on the assignment. I’m sure it’s because the second version allocates memory differently, but I’m starting to get a headache trying to figure out what’s what or how to get fix this. (I’m currently working around it by dynamically allocating a buffer of the same size as the pattern array, copying the pattern to the new buffer, making the changes to the buffer, using the buffer in the place of the pattern array, and then trying to remember to free the—temporary—buffer.) (Specifically, the original version cast the pattern array—+offset—to a DWORD* and assigned a DWORD constant to it to overwrite the four target bytes. The new version cannot do that since the length of the source is unknown—may not be four bytes—so it uses memcpy instead. I’ve checked and re-checked and have made sure that the pointers to memcpy are correct, but I still get an access violation. I use memcpy instead of str(n)cpy because I am using plain chars (as an array of bytes), not Unicode chars and ignoring the null-terminator. Using an assignment as above causes the same problem.) Any ideas? Thanks a lot.

    Read the article

  • Pointers to structures

    - by blacktooth
    typedef struct queue { int q[max]; int qhead; int qrear; } queue; void init_queue(queue *QUEUE) { QUEUE.qhead = 0; QUEUE.qrear = -1; } void enqueue(queue *QUEUE,int data) { QUEUE.qrear++; QUEUE.q[QUEUE.qrear] = data; } int process_queue(queue *QUEUE) { if(QUEUE.qhead > QUEUE.qrear) return -1; else return QUEUE.q[QUEUE.qhead++]; } I am implementing queues using arrays just to keep it simple. Wats the error with the above code?

    Read the article

  • Should I Make These Vectors Classes or Structs in C#

    - by dewald
    I am creating a geometry library in C# and I will need the following immutable types: Vector2f (2 floats - 8 bytes) Vector2d (2 doubles - 16 bytes) Vector3f (3 floats - 12 bytes) Vector3d (3 doubles - 24 bytes) Vector4f (4 floats - 16 bytes) Vector4d (4 doubles - 32 bytes) I am trying to determine whether to make them structs or classes. MSDN suggests only using a struct if the size if going to be no greater than 16 bytes. That reference seems to be from 2005. Is 16 bytes still the max suggested size? I am sure that using structs for the float vectors would be more efficient than using a class, but what should I do about the double vectors? Should I make them structs also to be consistent, or should I make them classes?

    Read the article

  • Setting a value through reflection is not working.

    - by Scott Chamberlain
    I am trying to set a value through reflection. I created this little test program struct headerIndexes { public int AccountNum{ get; set; } public int other { get; set; } public int items { get; set; } } static void Main(string[] args) { headerIndexes headers = new headerIndexes(); headers.AccountNum = 1; Console.WriteLine("Old val: {0}", headers.AccountNum); foreach (var s in headers.GetType().GetProperties()) { if (s.Name == "AccountNum") s.SetValue(headers, 99, null); } Console.WriteLine("New val: {0}", headers.AccountNum); Console.ReadKey(); } Steping thorugh the program i see it correctly does the command s.SetValue(headers, 99, null); however the value of headers.AccountNum stays at 1 when setValue is run. Am I missing a obvious step?

    Read the article

  • Array of structures CLI

    - by Nitroglycerin
    public value struct ListOfWindows { HWND hWindow; int winID; String^ capName; }; thats my structure now i have created an array of them: array<ListOfWindows ^> ^ MyArray = gcnew array<ListOfWindows ^>(5); now to test if that works i made a simple function: void AddStruct( ) { HWND temp = ::FindWindow( NULL, "Test" ); if( temp == NULL ) return; MyArray[0]->hWindow = temp; // debug time error.. return; } ERROR: An unhandled exception of type 'System.NullReferenceException' occurred in Window.exe Additional information: Object reference not set to an instance of an object. dont know what to do.. kinda new to CLI so if you can help please do.. Thanks.

    Read the article

  • Practical differences between classes and structs in .net (not conceptual)?

    - by Gulshan
    Whenever I tried to search about differences between classes and structs in C# or .net, I ended up with the conceptual overview of the two things like value type or the reference type, where the variables are allocated etc. But I need some practical differences. I have found some like different behavior of assignment operator, having constructors etc. Can anybody provide some more practical differences which will be directly useful while coding? Like the things works with one but not with other or same operation showing different behavior. And some common mistakes regarding these two. Also please suggest where to consider using a struct instead of a class. And where the structs should not be used.

    Read the article

  • how to join a set of XElements to the values of a struct?

    - by jcollum
    Let's say I have a struct that contains local environments: public struct Environments { public const string Dev = "DEV"; public const string Qa1 = "SQA"; public const string Prod1 = "PROD"; public const string Prod2 = "PROD_SA"; public const string Uat = "UAT"; } And I'd like to pull a set of XElements out of an xml doc, but only those elements that have a key that matches a value in a struct. this.environments =(from e in settings.Element("Settings").Element("Environments") .Elements("Environment") .Where( x => x.HasAttribute("name") ) join f in [struct?] on e.Attribute("name") equals [struct value?]).ToDictionary(...) How would I go about doing this? Do I need reflection to get the values of the constants in the struct?

    Read the article

  • Clean bindings with structs

    - by andyvn22
    I have a model class for which it makes quite a lot of sense to have NSSize and NSPoint instance variables. This is lovely. I'm trying to create an editing interface for this object. I'd like to bind to size.width and whatnot. This, of course, doesn't work. What's the cleanest, most Cocoa-y solution to this problem? Of course I could write separate accessors for the individual members of every struct I use, but it seems like there should be a better solution.

    Read the article

  • Why does this give a segmentation fault?

    - by nightcracker
    I'm stunned, why does this code give me a segmentation fault? #include <stdio.h> #define LIMIT 1500000 typedef struct { int p; int a; int b; } triplet; int main(int argc, char **argv) { int i; triplet triplets[LIMIT]; for (i = 0; i < 5; i++) { triplets[i].p = 9; // remove this line and everything works fine } printf("%d\n", triplets[15].p); return 0; } EDIT: After changing LIMIT to 150 I no longer get a segmentation fault, it prints random numbers instead.

    Read the article

  • ColdFusion static key/value list?

    - by richardtallent
    I have a database table that is a dictionary of defined terms -- key, value. I want to load the dictionary in the application scope from the database, and keep it there for performance (it doesn't change). I gather this is probably some sort of "struct," but I'm extremely new to ColdFusion (helping out another team). Then, I'd like to do some simple string replacement on some strings being output to the browser, looping through the defined terms and replacing the terms with some HTML to define the terms (a hover or a link, details to be worked out later, not important). Can anyone point me in the right direction of: How to define the stucture (if that is what I need for a key/value pair list) How to query at the application start-up and reuse the list properly The best way to do the string replacement

    Read the article

  • Initializing structs in C++

    - by Neil Butterworth
    As an addendum to this question, what is going on here: #include <string> using namespace std; struct A { string s; }; int main() { A a = {0}; } Obviously, you can't set a std::string to zero. Can someone provide an explanation (backed with references to the C++ Standard, please) about what is actually supposed to happen here? And then explain for example): int main() { A a = {42}; } Are either of these well-defined? Once again an embarrassing question for me - I always give my structs constructors, so the issue has never arisen before.

    Read the article

  • Python - network buffer handling question...

    - by Patrick Moriarty
    Hi, I want to design a game server in python. The game will mostly just be passing small packets filled with ints, strings, and bytes stuffed into one message. As I'm using a different language to write the game, a normal packet would be sent like so: Writebyte(buffer, 5); // Delimit type of message Writestring(buffer, "Hello"); Sendmessage(buffer, socket); As you can see, it writes the bytes to the buffer, and sends the buffer. Is there any way to read something like this in python? I am aware of the struct module, and I've used it to pack things, but I've never used it to actually read something with mixed types stuck into one message. Thanks for the help.

    Read the article

  • Counting distinct and duplicate attribute values in an array

    - by keruilin
    I have an array of users that's sorted in descending order based on total_points. I need to find the rank of each user in that array. The issue is that more than one user can have the same total points and, thus, the same rank. For example, three users could be in 3rd place with 200 Points. Here's my current code: class Leader < ActiveRecord::Base def self.points_leaders all_leaders = all_points_leaders # returns array of users sorted by total_points in desc order all_leaders_with_rank = [] all_leaders.each do |user| rank = all_leaders.index(user)+1 all_leaders_with_rank << Ldr.new(rank, user) # Ldr is a Struct end return all_leaders_with_rank end end How must I modify the code so that the correct rank is returned, and not just the value of the index position?

    Read the article

  • Mapping C structure to an XML element

    - by EFraim
    Suppose I have a structure in C or C++, such as: struct ConfigurableElement { int ID; char* strName; long prop1; long prop2; ... }; I would like to load/save it to/from the following XML element: <ConfigurableElement ID="1" strName="namedElem" prop1="2" prop2="3" ... /> Such a mapping can be trivially done in Java/C# or any other language with run-time reflection for the matter. Can it be done in any non-tedious way in C++ with macros/template trickery? Bonus points for handling nested structures/unions.

    Read the article

  • How can I store an inventory-like list of numbers?

    - by Rachel
    I've got a list of number that I need to keep track of. The numbers are loosely related, but represent distinctly different items. I'd like to keep a list of the numbers but be able to refer to them by name so that I can call them and use them where needed easily. Kind of like an inventory listing, where the numbers all refer to a part ID and I'd like to call them idPart1, idPart2, idPart3 so their purpose is easily identifiable when they are used. What would be the best way to do this? 1)Define a structure. Say, PartIds. A number of int members will be included, part1, part2 etc. To use, an instance of the structure will be created, values assigned to the members, and the numbers will be used by saying struct.member as needed. 2)Define an enumeration. Use part1, part2 as the enum literals. Store the actual values in a vector or list, each one at the index corresponding to the value of the number's name within the enum. Use the enum literals to retrieve the values, list[enumLit]. 3)Something completely different There's nothing else I need to do with the numbers - just look them up every once in a while. Since there's no processing, I kind of think a new class for them is overkill, but I'm willing to be convinced otherwise. Any suggestions?

    Read the article

  • Cant print contents of a custom file

    - by ZaZu
    Hello, Im trying to scan contents from a random file into an array in a structure. Then I want to print those contents on screen. (NOTE: The following code is from a bigger program, this is just a sample, but all structures and arrays used are needed as declared ) The contents of the file being tested are simply: 5 4 3 2 5 3 4 2 #include<stdio.h> #define first 500 #define sec 500 struct trial{ int f; int r; float what[first][sec]; }; int trialtest(trial *test); int trialdisplay(trial *test); main(){ trial test; trialtest(&test); trialdisplay(&test); } int trialtest(trial *test){ int z,x,i; FILE *inputf; inputf=fopen("randomfile.txt","r"); for(i=0;i<5;i++){ fscanf(inputf,"%f",&(*test).what[z][x]); } fclose(inputf); return 0; } int trialdisplay(trial *test){ int i,z,x; printf("printing\n\n\n"); for (i=0;i<10;i++){ printf("%f",(*test).what[z][x]); } return 0; } The problem is, I get this error whenever I run the code .. I cant really understand whats going on : Any suggestions ? Thanks alot !

    Read the article

  • Working with fields which can mutate or be new instances altogether

    - by dotnetdev
    Structs are usually used for immutable data, eg a phone number, which does not mutate, but instead you get a new one (eg the number 000 becoming 0001 would mean two seperate numbers). However, pieces of information like Name, a string, can either mutate (company abc changing its name to abcdef, or being given a new name like def). For fields like this, I assume they should reside in the mutable class and not an immutable structure? My way of structuring code is to have an immutable concept, like Address (any change is a new address completely), in a struct and then reference it from a class like Customer, since Customer always has an address. So I would put CompanyName, or Employer, in the class as it is mutable. But a name can either mutate and so be the same 1 instance, or a new name setup and while the company still owning the first name too. Would the correct pattern for assigning a new instance (eg a new company name but the old name still owned by the company) be?: string name = ""; string newName = new string(); newName = "new"; name = newName; And a mutation just the standard assignment pattern? Thanks

    Read the article

  • JNA Passing Structure By Reference Help

    - by tyeh26
    Hi all, I'm trying to use JNA to talk over a USB device plugged into the computer. Using Java and a .dll that was provided to me. I am having trouble with the Write function: C code: typedef struct { unsigned int id; unsigned int timestamp; unsigned char flags; unsigned char len; unsigned char data[16]; } CANMsg; CAN_STATUS canplus_Write( CANHANDLE handle, //long CANMsg *msg ); Java Equivalent: public class CANMsg extends Structure{ public int id = 0; public int timestamp = 0; public byte flags = 0; public byte len = 8; public byte data[] = new byte[16]; } int canplus_Write(NativeLong handle, CANMsg msg); I have confirmed that I can open and close the device. The close requires the NativeLong handle, so i am assuming that the CANMsg msg is the issue here. I have also confirmed that the device works when tested with C only code. I have read the the JNA documentation thoroughly... I think. Any pointers. Thanks all.

    Read the article

  • Syntax for finding structs in multisets - C++

    - by Sarah
    I can't seem to figure out the syntax for finding structs in containers. I have a multiset of Event structs. I'm trying to find one of these structs by searching on its key. I get the compiler error commented below. struct Event { public: bool operator < ( const Event & rhs ) const { return ( time < rhs.time ); } bool operator > ( const Event & rhs ) const { return ( time > rhs.time ); } bool operator == ( const Event & rhs ) const { return ( time == rhs.time ); } double time; int eventID; int hostID; int s; }; typedef std::multiset< Event, std::less< Event > > EventPQ; EventPQ currentEvents; double oldRecTime = 20.0; EventPQ::iterator ceItr = currentEvents.find( EventPQ::key_type( oldRecTime ) ); // no matching function call I've tried a few permutations to no avail. I thought defining the conditional equality operator was going to be enough.

    Read the article

  • C++ Beginner - Trouble using structs and constants!

    - by Francisco P.
    Hello everyone! I am currently working on a simple Scrabble implementation for a college project. I can't get a part of it to work, though! Check this out: My board.h: http://pastebin.com/J9t8VvvB The subroutine where the error lies: //Following snippet contained in board.cpp //I believe the function is self-explanatory... //Pos is a struct containing a char, y, a int, x and an orientation, o, which is not //used in this particular case void Board::showBoard() { Pos temp; temp.o = 0; for (temp.y = 'A'; temp.y < (65 + TOTAL_COLUMNS); ++temp.y) { for (temp.x = 1; temp-x < (1 + TOTAL_ROWS); ++temp.x) { cout << _matrix[temp].getContents(); } cout << endl; } } The errors returned on compile time: http://pastebin.com/bZv7fggq How come the error states that I am trying to compare two Pos when I am comparing chars and ints? I also really can't place these other errors... Thanks for your time!

    Read the article

< Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >