struct

Understanding typedef with struct [duplicate]

浪尽此生 提交于 2019-12-30 10:44:14
问题 This question already has answers here : typedef struct vs struct definitions [duplicate] (12 answers) Closed 3 years ago . I am getting a hard time understanding this sample of code: typedef struct node { int data; struct node * next; } node; typedef node * nodepointer; So, we are building the struct node using typedef... I assume we are doing this in order to initialize the struct without the "struct" keyword being necessary. I want to ask why in the struct definition we used the name "node

Equivalent of with(from Pascal) to C/C++

时光毁灭记忆、已成空白 提交于 2019-12-30 10:41:56
问题 What is the equivalent of with from Pascal language in C/C++ language? A with statement is a shorthand for referencing the fields of a record or the fields, properties, and methods of an object. Example With (Object) do begin Width:=200; Height:=300; end; Is Equivalent with: Object.Width=200; Object.Height=200; 回答1: I don't believe that there is any direct equivalent to that statement in c/c++. If your objective is to avoid repeatedly typing "Object", then I suppose you could use a reference

How to fread() structs?

余生长醉 提交于 2019-12-30 10:27:08
问题 struct book { unsigned short size_of_content; unsigned short price; unsigned char *content; }; Assume I have file that contains multiple book s, each has different size_of_content , price and content . How can I read them one book at a time and identify which book it is (check price, for example)? size_t nread2; struct book *buff = malloc(sizeof(struct book)); while( (nread2 = fread(buff, sizeof(struct book), 1, infp)) > 0 ) { printf("read a struct once \n"); } This is what I have so far. I

How to fread() structs?

百般思念 提交于 2019-12-30 10:26:40
问题 struct book { unsigned short size_of_content; unsigned short price; unsigned char *content; }; Assume I have file that contains multiple book s, each has different size_of_content , price and content . How can I read them one book at a time and identify which book it is (check price, for example)? size_t nread2; struct book *buff = malloc(sizeof(struct book)); while( (nread2 = fread(buff, sizeof(struct book), 1, infp)) > 0 ) { printf("read a struct once \n"); } This is what I have so far. I

Swift: Filtering an array of structures using UISearchController/Predicates

南楼画角 提交于 2019-12-30 09:30:10
问题 Wondering if someone could help me out with filtering using predicates in Swift. I have a somewhat messy datasource that I am using to populate a UITableView. The data source is an array of structures. The struct is defined as follows: struct Exercises { let category: String let name : String let x_seed: [Double] let y_seed: [Double] let hasMult: Bool } Now in my tableview controller I'm holding an array of structures that contains all of the data for the table. class MainTableViewController:

Is a struct {…}; a type or an unnamed variable?

…衆ロ難τιáo~ 提交于 2019-12-30 09:06:37
问题 Is the following, at file scope, a type declaration or an unnamed variable? struct student_s { char* name; int age; double height; struct student_s* next; }; If it is a type definition, then what is the difference with: typedef struct student_s { char* name; int age; double height; struct student_s* next; }; ? (Background: see my answer at Changing a variable from global to local - C, where I believe the first introduces an unnamed variable that is then optimized away by the compiler.) Note :

How to properly use cin.peek()

心不动则不痛 提交于 2019-12-30 08:25:10
问题 This function is supposed to read a fraction and place it in an array. If the user enters '0' the function is supposed to exit. I am trying to do this using the cin.peek() function but execution always goes into the if statement and doesn't allow the user to exit. How should I properly code this (I am open to not using peek(), I thought it was the simplest way of doing it.) Thanks! void enterFrac(Fraction* fracs[], int& index) { int n, d; char c, slash; cout << "Enter fractions (end by

C++: Constructor versus initializer list in struct/class

送分小仙女□ 提交于 2019-12-30 08:15:27
问题 An object of a struct/class (that has no constructor ) can be created using an initializer list . Why is this not allowed on struct/class with constructor ? struct r { int a; }; struct s { int a; s() : a(0) {} }; r = { 1 }; // works s = { 1 }; // does not work 回答1: No, an object with a constructor is no longer considered a POD (plain old data). Objects must only contain other POD types as non-static members (including basic types). A POD can have static functions and static complex data

Compiler gives error when struct is not initialized and if we try to access the property but not with variable [duplicate]

痞子三分冷 提交于 2019-12-30 08:15:22
问题 This question already has answers here : C# Structs: Unassigned local variable? (2 answers) Closed 2 years ago . I have one observation about struct. When I declare a property in Struct and if I don't initialize the Struct then it gives me the below error - "Use of unassigned local variable empStruct" PSeduo Code- struct EmpStruct { private int firstNumber; public int FirstNumber { get { return firstNumber; } set { firstNumber = value; } } public int SecondNumber; } Program.cs- EmpStruct

struct static member meaning/definition [closed]

本秂侑毒 提交于 2019-12-30 07:46:10
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . struct a{static int z;}l; (a is declared at file scope) I cant initialize the z using a initializer list. what does a static struct member mean? does z(name) have external linkage and public access as well? (I thought it meant you give it file scope and group it under a(and has public access through a object)?.