The program has to read and display data from a structure, the program does not throw error but in the exit it appears the name after garbage (spaces without assigning) and the last name when it is shown How can this be solved?
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
typedef struct {
long int cedula;
char nombre[15];
char apellido[15];
char telefono[8];
}Persona;
void cargar(Persona &per) {
printf(" Ingresar la c%cdula: ",130);
scanf("%ld",&per.cedula);
printf("Ingresar el nombre: ");
scanf("%s",&per.nombre[15]);
printf("Ingresar el apellido: ");
scanf("%s",&per.apellido[15]);
printf("Ingrese el tel%cfono: ",130);
scanf("%s",&per.telefono[8]);
}
void mostrar(Persona &per) {
printf("\n\nLa cedula es: %ld\n",per.cedula);
printf("El nombre es: %s\n",per.nombre);
printf("El apellido es: %s\n",per.apellido);
printf("El tel%cfono es: %s\n",130,per.telefono);
}
int darCedula(Persona per){
return per.cedula;
}
int main() {
Persona per;
cargar(per);
mostrar(per);
darCedula(per);
getch();
return 0;
}