// paso de puntero a estructuras a funciones
#include <stdio.h>
#define N 2
typedef struct{
char nombre[30];
char direccion[30];
int telf;
}dat[N];
void recogida(dat *datos); // recogida de datos
void muestra(dat *datos); // muestra de datos
int main(){
dat *pst = NULL;
pst = (dat *)malloc(2*sizeof(dat)); // reservo tamaño para este puntero
recogida(pst);
muestra(pst);
system("pause");
return 0;
}
void recogida(dat *datos){
int i;
for(i=0; i<N; i++){
printf("Persona %d: \n",i);
fflush(stdin);
printf("Introduce nombre: ");
gets(datos[i]->nombre); // string a campo nombre
printf("Introduce direccion: ");
gets(datos[i]->direccion); // string a campo direccion
printf("Introduce telefono: ");
scanf("%d",&datos[i]->telf);
}
}
void muestra(dat *datos){
int i;
for(i=0; i<N; i++){
printf("Persona %d \n",i);
printf("Nombre: %s || Direccion: %s || Telf: %d \n", datos[i]->nombre, datos[i]->direccion, datos[i]->telf);
}
}
Punt a struct con funciones: Direct telef
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario