davide92 Posted May 24, 2012 at 05:31 PM Report #457935 Posted May 24, 2012 at 05:31 PM Boas a todos gostaria de saber como posso escrever uma typedef struct num ficheiro binário de preferência sff. Abraço
HappyHippyHippo Posted May 24, 2012 at 05:38 PM Report #457937 Posted May 24, 2012 at 05:38 PM (edited) typedef struct Xpto { } Xpto; ... Xpto xpto; FILE * fd; ... fwrite(xpto, sizeof(Xpto), fd); Edited May 24, 2012 at 05:38 PM by HappyHippyHippo IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
davide92 Posted May 24, 2012 at 05:44 PM Author Report #457941 Posted May 24, 2012 at 05:44 PM (edited) Então no meu caso ponho assim ? #include <stdio.h> #define maxFICHA_DE_COMPONENTES 10000 #define maxFICHA_DE_POSTO_DE_TRABALHO 10000 #define maxFICHA_DE_FUNCIONARIO 10000 #define maxFICHA_DAS_OPERACOES 10000 #define maxFICHA_DA_EMPRESA 10000 int numeroFICHA_DE_COMPONENTES; int numeroFICHA_DE_POSTO_DE_TRABALHO; int numeroFICHA_DE_FUNCIONARIO; int numeroFICHA_DAS_OPERACOES; int numeroFICHA_DA_EMPRESA; int numeroDATA; typedef struct ficha_de_componentes { int id; char designacao[50]; char nserie[50]; DATA data; int garantia; int id_fornecedor; int id_fabricante; char tipo[50]; char condicao[50]; int id_posto_trabalho; char obs[100]; } FICHA_DE_COMPONENTES; FICHA_DE_COMPONENTES ficha_de_componentes [maxFICHA_DE_COMPONENTES]; FILE * componentes; fwrite(ficha_de_componentes, sizeof(ficha_de_componentes), componentes); Edited May 24, 2012 at 06:00 PM by davide92
davide92 Posted May 24, 2012 at 06:06 PM Author Report #457947 Posted May 24, 2012 at 06:06 PM Eu pus assim FILE *componentes; componentes = fopen("ficha_de_componentes.txt","a+"); fwrite(ficha_de_componentes,sizeof(ficha_de_componentes),componentes); e deu-me 1 erro error: too few arguments to function 'fwrite'
bsccara Posted May 24, 2012 at 06:54 PM Report #457957 Posted May 24, 2012 at 06:54 PM A função espera 4 parâmetros. Falta-te o numero de elementos, o terceiro: antes de ',componentes' põe ',1'.
HappyHippyHippo Posted May 24, 2012 at 08:33 PM Report #457973 Posted May 24, 2012 at 08:33 PM A função espera 4 parâmetros. Falta-te o numero de elementos, o terceiro: antes de ',componentes' põe ',1'. um gajo faz isto de cabeça da sempre bronca ... pois ... falta o número de elementos a gravar IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
davide92 Posted May 24, 2012 at 11:58 PM Author Report #458020 Posted May 24, 2012 at 11:58 PM E já agora porque o numero 1 ?
KTachyon Posted May 25, 2012 at 12:38 AM Report #458025 Posted May 25, 2012 at 12:38 AM Porque só estás a gravar 1 componente. Mais especificamente, 1 x sizeof(ficha_de_componentes). “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now