Search Results

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

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

  • Data Types and Structs

    - by dubya
    I'm reviewing for a test, and I am stumped by this question. Consider the following declarations: enum CategoryType {HUMANITIES, SOCIALSCIENCE, NATURALSCIENCE}; const int NUMCOURSES = 100; struct CourseRec { string courseName; int courseNum; CategoryType courseCategory; }; typedef CourseRec CourseList [NUMCOURSES]; CourseList courses; int index1, index2; What is the data type of the expression courses[index1] .courseName[index2] ? (a) CourseList (b) CourseRec (c) string (d) char (e) none; the expression is syntactically invalid I thought that the answer would be string, since courseName is a string, or maybe even CourseRec, since it is in the struct, but the answer is (d)char. Why is this a char data type? Any help is greatly appreciated.

    Read the article

  • passing structure directly to function

    - by ra170
    I have a struct that I initialize like this: typedef struct { word w; long v; } MyStruct; MyStruct sx = {0,0}; Update(sx); Now, it seems such a waste to first declare it and then to pass it. I know that in C#, there's a way to do everything in one line. Is there any possiblity of passing it in a more clever (read: cleaner) way to my update function?

    Read the article

  • Python: Unpack arbitary length bits for database storage

    - by sberry2A
    I have a binary data format consisting of 18,000+ packed int64s, ints, shorts, bytes and chars. The data is packed to minimize it's size, so they don't always use byte sized chunks. For example, a number whose min and max value are 31, 32 respectively might be stored with a single bit where the actual value is bitvalue + min, so 0 is 31 and 1 is 32. I am looking for the most efficient way to unpack all of these for subsequent processing and database storage. Right now I am able to read any value by using either struct.unpack, or BitBuffer. I use struct.unpack for any data that starts on a bit where (bit-offset % 8 == 0 and data-length % 8 == 0) and I use BitBuffer for anything else. I know the offset and size of every packed piece of data, so what is going to be the fasted way to completely unpack them? Many thanks.

    Read the article

  • C: Incompatible types?

    - by Airjoe
    #include <stdlib.h> #include <stdio.h> struct foo{ int id; char *bar; char *baz[6]; }; int main(int argc, char **argv){ struct foo f; f.id=1; char *qux[6]; f.bar=argv[0]; f.baz=qux; // Marked line return 1; } This is just some test code so ignore that qux doesn't actually have anything useful in it. I'm getting an error on the marked line, incompatible types when assigning to type ‘char *[6]’ from type ‘char **’ but both of the variables are defined as char *[6] in the code. Any insight?

    Read the article

  • C Structure Pointer Problem

    - by Halo
    I have this struct; #define BUFSIZE 10 struct shared_data { pthread_mutex_t th_mutex_queue; int count; int data_buffer_allocation[BUFSIZE]; int data_buffers[BUFSIZE][100]; }; and I want to allocate one of the data_buffers for a process, for that purpose I execute the following function; int allocate_data_buffer(int pid) { int i; for (i = 0; i < BUFSIZE; i++) { if (sdata_ptr->data_buffer_allocation[i] == NULL) { sdata_ptr->data_buffer_allocation[i] = pid; return i; } } return -1; } but the compiler warns me that I'm comparing pointer to a value. When I put a & in front of sdata_ptr it calms down but I'm not sure if it will work. Isn't what I wrote above supposed to be true?

    Read the article

  • a nicer way to create structs in a loop

    - by sandra
    Hi guys, I haven't coded in C++ in ages. And recently, I'm trying to work on something involving structs. Like this typedef struct{ int x; int y; } Point; Then in a loop, I'm trying to create new structs and put pointers to them them in a list. Point* p; int i, j; while (condition){ // compute values for i and j with some function... p = new Point; p* = {i, j}; //initialize my struct. list.append(p); //append this pointer to my list. } Now, my question is it possible to simplify this? I mean, the pointer variable *p outside of the loop and calling p = new Point inside the loop. Isn't there a better/nicer syntax for this?

    Read the article

  • Can someone explain how pointer to pointer works?

    - by user3549560
    I don't really understand how the pointer to pointer works. Any way to do the same work without using pointer to pointer? struct customer{ char name[20]; char surname[20]; int code; float money; }; typedef struct customer customer; void inserts(customer **tmp) { *tmp = (customer*)malloc(sizeof(customer)); puts("Give me a customer name, surname code and money"); scanf("%s %s %d %f", (*tmp)->name, (*tmp)->surname, &(*tmp)->code,&(*tmp)->money); }

    Read the article

  • design function: underlying structure to store list of results for print to file

    - by forest.peterson
    is this a good approach to print a list of items to csv file with a sublist attached to each item. The gist of the function is when an item is found that does not exactly macth then a list of close matches is generated - this works now writing out one list at a time to a command window. For export to a csv file I think all the lists must be generated, stored and then written at once. Right now I use a struct to store the attributes printed, each struct is an item on the list - these structs are then added to a sorted stack and when printed they pop off into write out. Is a stack of stacks of structs a good design?

    Read the article

  • Stucture with array of pointers in C

    - by MVTCplusplus
    What's wrong with this? Can I have an array of pointers to SDL_Surfaces in a struct in C? typedef struct { int next_wheel; int pos_X; int pos_Y; int front_wheel_pos_X; int front_wheel_pos_Y; int velocity; int rear_wheel_pos_X; int rear_wheel_pos_Y; SDL_Surface* body; SDL_Surface* rear_wheel[9]; SDL_Surface* front_wheel[9]; } mars_rover; ... mars_rover* init_rover() { mars_rover* rover = (mars_rover*)malloc(sizeof(mars_rover) + sizeof(SDL_Surface) * 19); ... return rover; } int main() { mars_rover* rover = init_rover(); ... }

    Read the article

  • Structs and pointers

    - by user1763861
    I have a few questions about structs and pointers For this struct: typedef struct tNode_t { char *w; } tNode; How come if I want to change/know the value of *w I need to use t.w = "asdfsd" instead of t->w = "asdfasd"? And I compiled this successfully without having t.w = (char *) malloc(28*sizeof(char)); in my testing code, is there a reason why tt's not needed? Sample main: int main() { tNode t; char w[] = "abcd"; //t.word = (char *) malloc(28*sizeof(char)); t.word = w; printf("%s", t.word); } Thanks.

    Read the article

  • C - How to manipulate typedef structure pointer?

    - by AbhishekJoshi
    typedef struct { int id; char* first; char* last; }* person; person* people; Hi. How can I use this above, all set globally, to fill people with different "person"s? I am having issues wrapping my head regarding the typedef struct pointer. I am aware pointers are like arrays, but I'm having issues getting this all together... I would like to keep the above code as is as well. Edit 1: char first should be char* first.

    Read the article

  • computing hash values, integral types versus struct/class

    - by aaa
    hello I would like to know if there is a difference in speed between computing hash value (for example std::map key) of primitive integral type, such as int64_t and pod type, for example struct { int16_t v[4]; };. I know this is going to implementation specific, so my question ultimately pertains to gnu standard library. Thanks

    Read the article

  • Read and write struct in C

    - by Sergey
    I have a struct: typedef struct student { char fname[30]; char sname[30]; char tname[30]; Faculty fac; int course; char group[10]; int room; int bad; } Student; I read it from the file: Database * dbOpen(char *fname) { FILE *fp = fopen(fname, "rb"); List *lst, *temp; Student *std; Database *db = malloc(sizeof(*db)); if (!fp) return NULL; FileNameS = fname; std = malloc(sizeof(*std)); if (!fread(std, sizeof(*std), 1, fp)) { db->head = db->tail = NULL; return db; } lst = malloc(sizeof(*lst)); lst->s = std; lst->prev = NULL; db->head = lst; while (!feof(fp)) { fread(std, sizeof(*std), 1, fp); temp = malloc(sizeof(*temp)); temp->s = std; temp->prev = lst; lst->next = temp; lst = temp; } lst->next = NULL; db->tail = lst; fclose(fp); return db; } And I have a problem... At the last record i have a such file pointer: `fp 0x10311448 {_ptr=0x00344b90 "???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? _ _iobuf * ` And i read last record 2 times... Save file code: void * dbClose(Database *db) { FILE *fp = fopen(FileNameS, "w+b"); List *lst, *temp; lst = db->head; while(lst != NULL) { fwrite(lst->s, sizeof(*(lst->s)), 1, fp); temp = lst; lst = lst->next; free(temp); } free(db); fclose(fp); }

    Read the article

  • Struct Array Initialization and String Literals

    - by Christian Ammer
    Is following array initialization correct? I guess it is, but i'm not really sure if i can use const char* or if i better should use std::string. Beside the first question, do the char pointers point to memory segments of same sizes? struct qinfo { const char* name; int nr; }; qinfo queues[] = { {"QALARM", 1}, {"QTESTLONGNAME", 2}, {"QTEST2", 3}, {"QIEC", 4} };

    Read the article

  • Finding an unnamed union in a struct::Haiku

    - by Freeman Lou
    So I have this assignment, and I have to find an unnamed union in struct _pthread_rwlock in pthread.h in the Haiku open source project. I began this assignment with some knowledge of c++ (past inheritance, polymorphism, and classes), but I find that what I learned do not help at all in my situation. I've opened the header file, and a source file named pthread_rwlock.cpp, and tried to look for the unnamed union, but there seems to be no unions in either file. What would be the correct way to find the problem?

    Read the article

  • have an array of struct in wsdl + php without using NSoap

    - by Shadi
    Hi, I want to have an array of struct (an array of books with their specifications like publication, ISBN number, ...). in wsdl and php. I have searched a little and I have found files that uses Nusoap, However, I dont want to use NuSoap. Is there any solution? I would appreciate if you help me in writing the related wsdl, client and server (php) files. Thank you so much. Best, shadi.

    Read the article

  • C++ struct sorting

    - by Betamoo
    I have a vector of custom Struct that needs to be sorted on different criteria each time Implementing operator < will allow only one criteria But I want to be able to specify sorting criteria each time I call C++ standard sort. How to do that? Please note it is better to be efficient in running time.. Thanks

    Read the article

  • C++: Return NULL instead of struct

    - by Rosarch
    I have a struct Foo. In pseudocode: def FindFoo: foo = results of search foundFoo = true if a valid foo has been found return foo if foundFoo else someErrorCode How can I accomplish this in C++? Edited to remove numerous inaccuracies.

    Read the article

  • Printing Arrays from Structs

    - by Carlll
    I've been stumped for a few hours on an exercise where I must use functions to build up an array inside a struct and print it. In my current program, it compiles but crashes upon running. #define LIM 10 typedef char letters[LIM]; typedef struct { int counter; letters words[LIM]; } foo; int main(int argc, char **argv){ foo apara; structtest(apara, LIM); print_struct(apara); } int structtest(foo *p, int limit){ p->counter = 0; int i =0; for(i; i< limit ;i++){ strcpy(p->words[p->counter], "x"); //only filling arrays with 'x' as an example p->counter ++; } return; I do believe it's due to my incorrect usage/combination of pointers. I've tried adjusting them, but either an 'incompatible types' error is produced, or the array is seemingly blank } void print_struct(foo p){ printf(p.words); } I haven't made it successfully up to the print_struct stage, but I'm unsure whether p.words is the correct item to be calling. In the output, I would expect the function to return an array of x's. I apologize in advance if I've made some sort of grievous "I should already know this" C mistake. Thanks for your help.

    Read the article

  • C/C++: Passing a structure by value, with another structure as one of its members, changes values of

    - by jellyfisharepretty
    Sorry for the confusing title, but it basically says it all. Here's the structures I'm using (found in OpenCV) : struct CV_EXPORTS CvRTParams : public CvDTreeParams { bool calc_var_importance; int nactive_vars; CvTermCriteria term_crit; CvRTParams() : CvDTreeParams( 5, 10, 0, false, 10, 0, false, false, 0 ), calc_var_importance(false), nactive_vars(0) { term_crit = cvTermCriteria( CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 50, 0.1 ); } } and typedef struct CvTermCriteria { int type; int max_iter; double epsilon; } CvTermCriteria; CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon ) { CvTermCriteria t; t.type = type; t.max_iter = max_iter; t.epsilon = (float)epsilon; return t; } Now, I initialize a CvRTParams structure and set values for its members : CvRTParams params; params.max_depth = 8; params.min_sample_count = 10; params.regression_accuracy = 0; params.use_surrogates = false; params.max_categories = 10; params.priors = priors; params.calc_var_importance = true; params.nactive_vars = 9; params.term_crit.max_iter = 33; params.term_crit.epsilon = 0.1; params.term_crit.type = 3; Then call a function of an object, taking params in as a parameter : CvRTrees* rt = new CvRTrees; rt->train(t, CV_ROW_SAMPLE, r, 0, 0, var_type, 0, params) What happens now ? Values of... params.term_crit.max_iter params.term_crit.epsilon params.term_crit.type have changed ! They are no longer 33, 0.1 and 3, but something along the lines of 3, 7.05541e-313 and 4, and this, for the whole duration of the CvRtrees::train() function...

    Read the article

  • Do all C compilers allow functions to return structures?

    - by Jordan S
    I am working on a program in C and using the SDCC compiler for a 8051 architecture device. I am trying to write a function called GetName that will read 8 characters from Flash Memory and return the character array in some form. I know that it is not possible to return an array in C so I am trying to do it using a struct like this: //********************FLASH.h file******************************* MyStruct GetName(int i); //Function prototype #define NAME_SIZE 8 typedef struct { char Name[NAME_SIZE]; } MyStruct; extern MyStruct GetName(int i); // *****************FLASH.c file*********************************** #include "FLASH.h" MyStruct GetName( int i) { MyStruct newNameStruct; //... // Fill the array by reading data from Flash //... return newNameStruct; } I don't have any references to this function yet but for some reason, I get a compiler error that says "Function cannot return aggregate." Does this mean that my compiler does not support functions that return structs? Or am I just doing something wrong?

    Read the article

  • Coordinating typedefs and structs in std::multiset (C++)

    - by Sarah
    I'm not a professional programmer, so please don't hesitate to state the obvious. My goal is to use a std::multiset container (typedef EventMultiSet) called currentEvents to organize a list of structs, of type Event, and to have members of class Host occasionally add new Event structs to currentEvents. The structs are supposed to be sorted by one of their members, time. I am not sure how much of what I am trying to do is legal; the g++ compiler reports (in "Host.h") "error: 'EventMultiSet' has not been declared." Here's what I'm doing: // Event.h struct Event { public: bool operator < ( const Event & rhs ) const { return ( time < rhs.time ); } double time; int eventID; int hostID; }; // Host.h ... void calcLifeHist( double, EventMultiSet * ); // produces compiler error ... void addEvent( double, int, int, EventMultiSet * ); // produces compiler error // Host.cpp #include "Event.h" ... // main.cpp #include "Event.h" ... typedef std::multiset< Event, std::less< Event > > EventMultiSet; EventMultiSet currentEvents; EventMultiSet * cePtr = &currentEvents; ... Major questions Where should I include the EventMultiSet typedef? Are my EventMultiSet pointers obviously problematic? Is the compare function within my Event struct (in theory) okay? Thank you very much in advance.

    Read the article

  • Fast serialization/deserialization of structs

    - by user256890
    I have huge amont of geographic data represented in simple object structure consisting only structs. All of my fields are of value type. public struct Child { readonly float X; readonly float Y; readonly int myField; } public struct Parent { readonly int id; readonly int field1; readonly int field2; readonly Child[] children; } The data is chunked up nicely to small portions of Parent[]-s. Each array contains a few thousands Parent instances. I have way too much data to keep all in memory, so I need to swap these chunks to disk back and forth. (One file would result approx. 2-300KB). What would be the most efficient way of serializing/deserializing the Parent[] to a byte[] for dumpint to disk and reading back? Concerning speed, I am particularly interested in fast deserialization, write speed is not that critical. Would simple BinarySerializer good enough? Or should I hack around with StructLayout (see accepted answer)? I am not sure if that would work with array field of Parent.children. UPDATE: Response to comments - Yes, the objects are immutable (code updated) and indeed the children field is not value type. 300KB sounds not much but I have zillions of files like that, so speed does matter.

    Read the article

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