1
Why is this syntax wrong:
#include <stdio.h>
typedef struct {
char* nome;
char* numero;
}Agenda;
void adiciona(Agenda* reg, int i) {
scanf("%s", reg[i]->nome);
scanf("%s", reg[i]->numero);
}
void imprime(Agenda* reg, int i) {
for(int j = 0; j < i; j++) {
printf("Nome: %s | ", reg[j]->nome);
printf("Numero: %s\n", reg[j]->numero);
}
}
int main() {
int sair = 0;
int i = 0;
Agenda registro[10];
while(!sair) {
int escolha;
printf("O que voce deseja ? (1)Inserir (2)Imprimir (3)Sair\n");
scanf("%d", &escolha);
switch(escolha) {
case 1:
adiciona(registro, i);
i++;
break;
case 2:
imprime(registro, i);
break;
case 3:
sair = 1;
break;
}
}
}
And why when I ask to print the name and the contact comes out some strange characters and if it is more of a repeated sai? That is, as if the first position and the second of the vector had the same value.
Thank you bigown =D
– Otavio Augusto