-2
This is a program that I’ve been doing for presentation only that part of it is making mistakes that I haven’t been able to solve.
Here is the . h:
#ifndef PROJETOIAPG_PROJETO_H
#define PROJETOIAPG_PROJETO_H
#define TAM_S 30
typedef struct cliente {
char nome[15], sobrenome[15];
int id;
} CLIENTE;
int inicializacao();
int ler_clientes(CLIENTE cliente[]);
#endif
And here’s the . c
#include stdlib.h
#include projeto.h
#include stdio.h
int inicializacao(){
CLIENTE cliente;
ler_clientes(&cliente);
menu_principal();
return 0;
}
int ler_clientes(CLIENTE cliente[]) {
int i=0,num_c=0;
FILE fp;
fp = fopen(Clientes.txt,r);
if( fp == NULL ) {
printf(nErro!n);
}
else
{
fscanf(fp , %dn , &num_c);
for(i=1;inum_c+1;i++)
{
fscanf(fp , %d , &cliente[i].id);
fscanf(fp , %s , &cliente[i].nome);
fscanf(fp , %sn , &cliente[i].sobrenome);
printf(nid%d , cliente[i].id);
printf(nnome%s , cliente[i].nome);
printf(nsobrenome%s , cliente[i].sobrenome);
}
}
fclose(fp);
return 0;
}
The.txt Clients file looks like this:
5
1 Manuel Monteiro
2 Maria Fernandes
3 Ines Cornio
4 Fernanda Guimaraes
5 Fernanda Guimaraes
The problem is that I haven’t been able to solve the error yet, since the most I’ve done so far is to reduce the . h the size of the character name[30] for 15 and now it is possible to run to the end but still gives the error:
Process finished with Exit code -1073740791 (0xC0000409)
Welcome to Stack Overflow in English. Please click edit and translate the question.
– Luiz Augusto
Sorry, I didn’t know the site existed in en. It is translated.
– Ana Patricia
The parameter referring to the format of your fscanf and printf functions is a string and therefore must be in quotes. As you say the program is working then I think there was a transcription error because, in this way, it would not compile.
– anonimo