Juin Posted January 1, 2010 at 03:24 PM Report Share #303552 Posted January 1, 2010 at 03:24 PM switch (op){ case 1: printf("Nao Urgente selecionado.\n"); strncpy(dados.urgencia,"Nao Urgente",NCHAR); break; case 2: printf("Urgente selecionado.\n"); strncpy(dados.urgencia,"Urgente",NCHAR); break; case 3: printf("Muito Urgente selecionado.\n"); strncpy(dados.urgencia,"Muito Urgente",NCHAR); break; default: printf("Tem de seleccionar um numero valido. Escolha de 1, 2 ou 3.\n"); break; } Quando uso o strncpy neste caso como sugeriram-me dá erro no sistema... Estou a usar correctamente? Link to comment Share on other sites More sharing options...
Baderous Posted January 1, 2010 at 03:32 PM Report Share #303554 Posted January 1, 2010 at 03:32 PM Que erro dá? Link to comment Share on other sites More sharing options...
Localhost Posted January 1, 2010 at 03:43 PM Report Share #303555 Posted January 1, 2010 at 03:43 PM Lembra-te que tens de incluir o header string.h here since 2009 Link to comment Share on other sites More sharing options...
Juin Posted January 1, 2010 at 03:56 PM Author Report Share #303556 Posted January 1, 2010 at 03:56 PM tenho o string.h incluido da um erro do windows Link to comment Share on other sites More sharing options...
Localhost Posted January 1, 2010 at 04:08 PM Report Share #303557 Posted January 1, 2010 at 04:08 PM Se NCHAR for maior do que o número de caracteres que dados.urgencia pode comportar a strncpy é exactamente igual à strcpy, poderá ser um problema em que estejas a passar do número de caracteres que dados.urgencia possa suportar. NCHAR tem de ser igual ao número de caracteres de dados.urgencia! here since 2009 Link to comment Share on other sites More sharing options...
Juin Posted January 1, 2010 at 04:38 PM Author Report Share #303566 Posted January 1, 2010 at 04:38 PM hum... mas uso para outros fins tipo nomes endereços :/ Link to comment Share on other sites More sharing options...
Localhost Posted January 1, 2010 at 04:41 PM Report Share #303567 Posted January 1, 2010 at 04:41 PM Pois, tens de avaliar consoante o que pretendes, podes aumentar o tamanho do buffer, mas já sabes que se a diferença entre o máximo que puseste no strncpy e o máximo que a string pode comportar der > 0 podes ter o perigo de ter um buffer overflow... Edit: Se usares a string para muita coisa o teu programa torna-se confuso, foi isso que eu percebi que estavas a querer dizer, se usas strings diferentes, podes consoante a string que fores copiar não usar o NCHAR, aliás aconselho-te a não usar um valor fixo! here since 2009 Link to comment Share on other sites More sharing options...
Juin Posted January 1, 2010 at 04:52 PM Author Report Share #303568 Posted January 1, 2010 at 04:52 PM pois afinal o nchar nao faz qualquer diferença, o erro do sistema deve ser da abertura do ficheiro :/ //EscreverFicheiro(dados,"basedados.txt","m"); //EscreverProposta(dados,aut,index); void EscreverProposta(Livro info, int aut, int indx){ int i; printf("Requesitante: %s\n", info.requisitante); printf("Data: %d/%d/%d", info.dia, info.mes, info.ano); for(i=0; i<aut; i++) printf("Autores: %s\n\n", info.autores[i][NCHAR]); printf("Titulo: %s",info.titulo[NCHAR]); printf("Coleccao: %s\n\n", info.coleccao[NCHAR]); printf("Data de Publicacao: %d/%d/%d\n\n", info.diapub, info.mespub, info.anopub); printf("Edicao: %d º Edicao\n\n", info.edicao); printf("Preco: %.2f €\n\n", info.preco); printf("Editor: %s\n\n", info.editor); printf("Endereco Editor: %s\n\n", info.EndEditor); printf("Numero de Exemplares: %d\n\n", info.NumDeExemplares); printf("ISBN/ISSN: %d\n\n", info.ISBN); printf("Urgencia: %s\n\n", info.urgencia); printf("Chave: %d", indx); } void EscreverFicheiro(Livro propostas, char *basedadosf, char *m){ FILE *f; int i; f=fopen(basedadosf, m); if (f==NULL){ printf("ERRO DE ABERTURA DO FICHEIRO!\n"); return; } fprintf(f,"%s; %d/%d/%d; %s; %d; %d/%d/%d; %d; %.2f; %s; %s; %s\n", propostas.requisitante, propostas.dia, propostas.mes, propostas.ano, propostas.titulo, propostas.edicao, propostas.diapub, propostas.mespub, propostas.anopub, propostas.coleccao, propostas.ISBN, propostas.preco, propostas.editor, propostas.EndEditor, propostas.urgencia); for(i=0; i<4 ;i++) fprintf(f,"%s;\n", propostas.autores[i]); fclose(f); } Link to comment Share on other sites More sharing options...
Localhost Posted January 1, 2010 at 04:59 PM Report Share #303570 Posted January 1, 2010 at 04:59 PM Sim, estás a abrir o ficheiro de uma maneira inválida que é m, acho que isso não existe f=fopen(basedadosf, m); if (f==NULL){ printf("ERRO DE ABERTURA DO FICHEIRO!\n"); return; } here since 2009 Link to comment Share on other sites More sharing options...
Juin Posted January 1, 2010 at 05:09 PM Author Report Share #303572 Posted January 1, 2010 at 05:09 PM mas na aula abrimos com este tipo de abertura :/ Link to comment Share on other sites More sharing options...
Baderous Posted January 1, 2010 at 05:10 PM Report Share #303573 Posted January 1, 2010 at 05:10 PM Ou muito me engano ou estes printfs estão mal: printf("Autores: %s\n\n", info.autores[NCHAR]); printf("Titulo: %s",info.titulo[NCHAR]); printf("Coleccao: %s\n\n", info.coleccao[NCHAR]); Link to comment Share on other sites More sharing options...
Localhost Posted January 1, 2010 at 05:12 PM Report Share #303574 Posted January 1, 2010 at 05:12 PM Baderous, eu já tinha dito isso no tópico dele anterior, eu acho que ele não deve pôr o indice ali xD Já tinha dito isso... Abriram com m? Acho que estás equivocado: olha esta lista Lista de tipos de abertura de ficheiros Ah, também faltam as aspas... here since 2009 Link to comment Share on other sites More sharing options...
Baderous Posted January 1, 2010 at 05:22 PM Report Share #303576 Posted January 1, 2010 at 05:22 PM O tipo de abertura não é "m", m é uma string que é argumento da função que chama a fopen. Link to comment Share on other sites More sharing options...
Juin Posted January 1, 2010 at 05:22 PM Author Report Share #303577 Posted January 1, 2010 at 05:22 PM estou a copiar de um ficheiro que fizemos na escola muito parecido e no qual funcionava se querem que vos mande para comproarem :/ Link to comment Share on other sites More sharing options...
Localhost Posted January 1, 2010 at 05:24 PM Report Share #303578 Posted January 1, 2010 at 05:24 PM E não necessita de pôr o tipo de abertura? here since 2009 Link to comment Share on other sites More sharing options...
Juin Posted January 1, 2010 at 05:32 PM Author Report Share #303581 Posted January 1, 2010 at 05:32 PM colocavamos m char* m Link to comment Share on other sites More sharing options...
Localhost Posted January 1, 2010 at 05:38 PM Report Share #303585 Posted January 1, 2010 at 05:38 PM Mas esse tipo de abertura não existe! A única explicação é aquela que o Baderous disse e mesmo assim acho que está mal porque tens de dizer qual o tipo de abertura... E faltam-te as aspas here since 2009 Link to comment Share on other sites More sharing options...
Baderous Posted January 1, 2010 at 06:23 PM Report Share #303590 Posted January 1, 2010 at 06:23 PM Localhost, o meu último post era para ti. O fopen está correcto, a string m é recebida como argumento da função EscreverFicheiro. Já alteraste aquele problema dos printfs que eu tinha indicado? Link to comment Share on other sites More sharing options...
Localhost Posted January 1, 2010 at 06:24 PM Report Share #303591 Posted January 1, 2010 at 06:24 PM Eu sei que era para mim e eu perguntei se não era preciso o tipo de abertura do ficheiro. here since 2009 Link to comment Share on other sites More sharing options...
Juin Posted January 1, 2010 at 06:54 PM Author Report Share #303593 Posted January 1, 2010 at 06:54 PM qual problema nos prints? Link to comment Share on other sites More sharing options...
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