struct

Why should I use fflush(stdin) in this program?

ぐ巨炮叔叔 提交于 2021-01-27 07:21:46
问题 I know that it is use to clean the keyboard buffer, but I don't understand when/why I need to use it or if I really need to. For example, into this code that I made for my class, it only works if I put fflush(stdin) into the main function right after the while , and I only know this because the professor told me to do so after I had showed him the erro. Does the problem have something related with the struct and thats why I should use fflush(stdin) ? Here is the code: #include <stdio.h>

Empty structs in C

烂漫一生 提交于 2021-01-27 06:50:49
问题 http://c0x.coding-guidelines.com/6.7.2.1.html: 1401 If the struct-declaration-list contains no named members, the behavior is undefined. Does this mean that the following is illegal? struct C { }; Or what does it mean? I used a Convention=>C Ada pointer to an empty struct (in fact empty Ada record) to serve instead void* in my bindings of a C library (because there is no void* in Ada). I wonder if this is incorrect. What do I misunderstand? See also "Do not pass or return structs with no

Empty structs in C

巧了我就是萌 提交于 2021-01-27 06:50:10
问题 http://c0x.coding-guidelines.com/6.7.2.1.html: 1401 If the struct-declaration-list contains no named members, the behavior is undefined. Does this mean that the following is illegal? struct C { }; Or what does it mean? I used a Convention=>C Ada pointer to an empty struct (in fact empty Ada record) to serve instead void* in my bindings of a C library (because there is no void* in Ada). I wonder if this is incorrect. What do I misunderstand? See also "Do not pass or return structs with no

How to have a Struct with template with a class

杀马特。学长 韩版系。学妹 提交于 2021-01-27 05:41:01
问题 With this code (just a class of test): typedef unsigned short UInt16; template<class T> class CClass { public: SValue* getNewSValue(void); private: typedef struct { T *mValue; T *next; T *previous; UInt16 index; } SValue; }; template<typename T> SValue* CClass<T>::getNewSValue(void) { return new SValue; } I have the following errors: error C2143: syntax error : missing ';' before '*' error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Is it possible to

How to have a Struct with template with a class

♀尐吖头ヾ 提交于 2021-01-27 05:39:21
问题 With this code (just a class of test): typedef unsigned short UInt16; template<class T> class CClass { public: SValue* getNewSValue(void); private: typedef struct { T *mValue; T *next; T *previous; UInt16 index; } SValue; }; template<typename T> SValue* CClass<T>::getNewSValue(void) { return new SValue; } I have the following errors: error C2143: syntax error : missing ';' before '*' error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Is it possible to

How to wrap C structs in Cython for use in Python?

天大地大妈咪最大 提交于 2021-01-27 04:07:33
问题 For a bit of learning experience, I'm trying to wrap a few parts of SDL (1.2.14) in Cython in an extension for Python 3.2. I am having a problem figuring out how to wrap C structs straight into Python, being able to access its attributes directly like: struct_name.attribute For example, I want to take the struct SDL_Surface: typedef struct SDL_Rect { Uint32 flags SDL_PixelFormat * format int w, h Uint16 pitch void * pixels SDL_Rect clip_rect int refcount } SDL_Rect; And be able to use it like

Error when initializing a struct with a brace-enclosed initializer list

眉间皱痕 提交于 2021-01-27 02:38:24
问题 struct CLICKABLE { int x; int y; BITMAP* alt; BITMAP* bitmap; CLICKABLE() { alt=0; } }; CLICKABLE input={1,2,0,0}; This code gives me the following error: Could not convert from brace-enclosed initializer list Could someone explain me why the compiler is giving me this error, and how I can fix it? I'm still learning the language. 回答1: Your class has a constructor, so it isn't an aggregate, meaning you cannot use aggregate initialization. You can add a constructor taking the right number and

Error when initializing a struct with a brace-enclosed initializer list

杀马特。学长 韩版系。学妹 提交于 2021-01-27 02:37:40
问题 struct CLICKABLE { int x; int y; BITMAP* alt; BITMAP* bitmap; CLICKABLE() { alt=0; } }; CLICKABLE input={1,2,0,0}; This code gives me the following error: Could not convert from brace-enclosed initializer list Could someone explain me why the compiler is giving me this error, and how I can fix it? I'm still learning the language. 回答1: Your class has a constructor, so it isn't an aggregate, meaning you cannot use aggregate initialization. You can add a constructor taking the right number and

Mutable structs in a vector

▼魔方 西西 提交于 2021-01-27 02:16:44
问题 I'm trying to create a vector to keep track of enemies in a game that will hold a bunch of mutable structs. I have a world struct that has the enemies as a member of it as follows: pub struct World { pub player : Creature, pub enemies : Vec<Creature>, } I create the enemies vector as follows: let mut enemies = vec![]; let mut enemy = Creature::new(5, 5, map_start_x+5, map_start_y+5, "$", 10, 1, "") enemies.push(enemy); later on in the code when I pull out an individual enemy from enemies for

struct.error: unpack requires a buffer of 4 bytes

自古美人都是妖i 提交于 2021-01-24 07:54:44
问题 I want to convert data from a device from bites to float I use the code from this answer bytes to float import struct byte_file = b'+001.80\r' print(type(byte_file)) y = struct.unpack('f' , byte_file) print(y) I get this struct.error: unpack requires a buffer of 4 bytes The correct outcome should be 1.80 do I need to implement a buffer argument ? 回答1: struct is used for binary packed data - data that is not human-readable. b'+001.80\r' is 8 bytes long: b'+', b'0', b'0', b'1', b'.', ... . You