Good evening guys.
I'm having a problem with a simple code, for a college job where I can not figure out why, since Dev-C ++ does not report any errors. To prevent someone from my college find this topic by chance and copy my code, I will use an example of the teacher himself, with the addition of what is giving error in my:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TAM 3
typedef struct{
int cod;
char nome[50];
char telefone[20];
} tipo_pessoa;
int main(){
tipo_pessoa lista[TAM];
int i=0;
for(i=0; i<TAM; i++){
printf("Insira o nome da pessoa %d:\n", i+1);
gets(lista[i].nome);
fflush(stdin);
printf("Insira o telefone de pessoa %d (XX XXXXX XXXX):\n", i+1);
gets(lista[i].telefone);
fflush(stdin);
lista[i].cod = i+1;
}
system("cls");
printf("Os cadastros foram preenchidos...\n\n");
system("pause");
for(i=0; i<TAM; i++){
printf("%s - %s - %s\n", lista[i].cod, lista[i].nome, lista[i].telefone);
}
}
My problem is with lista[i].cod
, which when trying to "print" on the screen, the program finishes on time. If I take out lista[i].cod
of printf
, the code runs normally. If I ask the user to specify the number, it returns a strange character, but still, I need the code to be automatically generated by system
and need to be displayed in printf
.
What am I doing wrong?
I'm sorry if it's something stupid I can not see, but I've been pounding my head for 4 hours.