structure

C++ - How to write and read a structure that contain an object ? (to write and read binary)

断了今生、忘了曾经 提交于 2019-11-28 12:56:25
问题 I'm trying to write a C structure in a file (to write in binary) and read it to recover it. I don't know if it is possible. Here is what I have : head.hh: #include <iostream> typedef struct s_test { char cmd[5]; std::string str; }t_test; main.cpp: #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include "head.hh" int main() { t_test test; int fd = open("test", O_APPEND | O_CREAT | O_TRUNC | O_WRONLY, 0666); test.cmd[0] = 's'; test.cmd[1] = 'm'; test.cmd[2]

Are there any size limitations for C structures?

浪尽此生 提交于 2019-11-28 12:00:58
Are there any size limitations for C structures? Alexey Frunze From the C standard: 5.2.4.1 Translation limits 1 The implementation shall be able to translate and execute at least one program that contains at least one instance of every one of the following limits: ... — 65535 bytes in an object (in a hosted environment only) ... — 1023 members in a single structure or union ... — 63 levels of nested structure or union definitions in a single struct-declaration-list ... 13) Implementations should avoid imposing fixed translation limits whenever possible. Other than that, the upper bound is

Reading/Writing a structure into a binary file

谁说胖子不能爱 提交于 2019-11-28 09:31:25
I am running a program with 3 structures and what I am doing to read/write in the binary file is the following: struct Medico { int Id_Doctor; int Estado; char Nombre[60]; char Clave_Acceso[20]; char Especialidad[40]; struct Medico *next; }; typedef struct Medico *Medicazos; typedef struct Medico Meds; Medicazos Nuevo; FILE *Archivaldo; char especialida[40], password[20]; char nombre_doc[60]; int estado_doc, id_doc; Archivaldo=fopen("md.dat", "rb"); fclose(Archivaldo); if((Archivaldo=fopen("md.dat", "rb"))==NULL) { printf("No se pudo abrir el archivo de Medicos\n"); //couldnt open file msg

Cocoa Objective-c Property C structure assign fails

泄露秘密 提交于 2019-11-28 07:01:46
I want to change the variable value which is a member of a structure of another class. But the value is not getting changed. Here is the code. //Structure.. typedef struct { int a; double b; } SomeType; //Class which has the structure as member.. @interface Test2 : NSObject { // Define some class which uses SomeType SomeType member; } @property SomeType member; @end @implementation Test2 @synthesize member; @end //Tester file, here value is changed.. @implementation TesstAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Insert code here

Refactoring Ruby on Rails i18n YAML files using dictionaries

假装没事ソ 提交于 2019-11-28 06:22:40
This StackOverflow question gave me food for thought on what is a good structure for Rails i18n files, so I thought I'd share another structure for refactoring Rails i18n yml files for your consideration/criticism. Given that I would like to keep the default app structure so I can use shorthand "lazy" lookups like t('.some_translation') in my views, as well as have an idea where translations are used in the app, avoid as much string repetition as possible, in particular with words that are not just the same, but also have identical contexts/meanings, only have to change a key once to have it

C pointer math with structures

时光总嘲笑我的痴心妄想 提交于 2019-11-28 06:20:05
问题 Trying to learn pointer math better I wrote this code. The intention was to increment the pointer threw the structure and print it's members. I know how to print it's member easier ways but would really like to know how my pointer math is messed up. Thank you. typedef struct{ int num; int num2; char *string; } astruct ; int main (int argc, const char * argv[]) { astruct mystruct = { 1234, 4567,"aaaaaaa"}; astruct *address; address = &mystruct; // this does print 1234 printf("address 0x%x has

Angular2 How to clean up the AppModule

落花浮王杯 提交于 2019-11-28 06:04:56
I've been using the tutorials online and created an 'ok' SPA data entry application. I have it connecting to my WEB API fine but have only built out one Model and already my AppModule has quiet a few lines. I'm thinking forward and using the current method I think the AppModule will be a crazy size once i finish with it, tough to read and possibly even tougher to debug. Have I possibly missed the point of how to structure an Angular2 larger application? I'm struggling to find a tutorial/project online that is larger than 1 component for reference. Below is my app.module.ts and folder structure

C# P/Invoke: Marshalling structures containing function pointers

和自甴很熟 提交于 2019-11-28 06:00:51
Sorry for the verbose introduction that follows. I need insight from someone knowing P/Invoke internals better than I do. Here is how I'm marshalling structures containing function pointers from C to C#. I would like to know whether it's the cleanest and/or most efficient way of doing it. I'm interfacing with a native DLL coded in C that provides the following entry point: void* getInterface(int id); You have to pass getInterface(int) one of the following enum values: enum INTERFACES { FOO, BAR }; Which returns a pointer to a structure containing function pointers like: typedef struct IFOO {

What is predicate in C++? [closed]

寵の児 提交于 2019-11-28 04:40:33
Can you give some example or a link to a topic. Andrey Sidorov A predicate is a C++ function returning a boolean or an object having a bool operator() member. A unary predicate takes one argument, a binary takes two, and so on. Examples of questions predicates can answer for a particular algorithm are: Is this element what we are looking for? Is the first of two arguments ordered first in our order? Are the two arguments equal? Almost all STL algorithms take a predicate as last argument. You can construct new predicates using standard, self-defined, and/or predicate-making classes ( here is a

Initializing a pointer to a structure

て烟熏妆下的殇ゞ 提交于 2019-11-28 03:54:53
问题 another linked question is Segmentation fault while using strcpy()? I have a structure: struct thread_data{ char *incall[10]; int syscall arg_no; int client_socket; }; How do I initialize a pointer to a structure of type above as well as initialize the pointer to the 10 strings (incall[]) inside the structure. Do I first initialize the strings and then the structure. Thanks. An edit: I guess I used the wrong word and should have said allocate. Actually I am passing this structure as an