#include <stdio.h> #include <stdlib.h> //* * ESTRUCTURAS * * //Declaramos la estructura struct datos { int codigo; char nombre[15]; }; int main(int argc, char *argv[]) { //Variable   struct datos  persona ; //PARA METER VALORES   printf(&quot;Introduce el codigo:&quot;); scanf(&quot;%d&quot;,  &persona.codigo ); fflush(stdin); printf(&quot;Introduce el nombre:&quot;); gets( persona.nombre ); system(&quot;PAUSE&quot;); return 0; } #include <stdio.h> #include <stdlib.h> //* * ESTRUCTURAS CON PUNTEROS * * //Declaramos la estructura struct datos { int codigo; char nombre[15]; }; int main(int argc, char *argv[]) { //Variable struct datos  persona ; //Puntero   struct datos  * p ; //Inicializar puntero p = &per ; //PARA METER VALORES printf(&quot;Introduce el codigo:&quot;); scanf(&quot;%d&quot;, &p->codigo ); fflush(stdin); printf(&quot;Introduce el nombre:&quot;); gets( p->nombre ); system(&quot;PAUSE&quot;); return 0; }
#include <stdio.h> #include <stdlib.h> //* *ARRAYS DE ESTRUCTURAS CON PUNTEROS * * //Declaramos la estructura struct datos { int codigo; char nombre[15];  }; int main(int argc, char *argv[]) { int i; struct datos  array[3]; //Puntero struct datos  *p ; //Inicializar puntero p = array ; //RECORRER ARRAY PARA METER VALORES for(i=0;i<3;i++) { printf(&quot;Introduce el codigo:&quot;); scanf(&quot;%d&quot;, &(p+i)->codigo ); fflush(stdin); printf(&quot;Introduce el nombre&quot;); gets( (p+i)->nombre ); }  system(&quot;PAUSE&quot;); return 0; } #include <stdio.h> #include <stdlib.h> //* * ESTRUCTURAS CON PUNTEROS * * //Declaramos la estructura struct datos { int codigo; char nombre[15]; }; int main(int argc, char *argv[]) { struct datos  per ; //Puntero  struct datos  *p ; //Inicializar puntero p =& per ; //PARA METER VALORES printf(&quot;Introduce el codigo:&quot;); scanf(&quot;%d&quot;, &p->codigo ); fflush(stdin); printf(&quot;Introduce el nombre:&quot;); gets( p->nombre ); system(&quot;PAUSE&quot;); return 0; }
#include <stdio.h> #include <stdlib.h> #define t  3  struct datos { int codigo; char nombre[15];  }; void LEER(struct datos *p) { int i; printf(&quot;\n* * LEER VALORES EN LA ESTRUCTURA * *&quot;);  for(i=0;i<t;i++) {  printf(&quot;\nCodigo: &quot;); scanf(&quot;%d &quot;,&(p+i)->codigo  ); printf(&quot;Nombre: &quot;); fflush(stdin); gets(  (p+i)->nombre ); }  } void IMPRIMIR(struct datos *p) { int i; printf(&quot;\n* * IMPRIMIR EL CONTENIDO DE LA ESTRUCTURA * *&quot;); for (i=0;i<t;i++) {  printf(&quot;\nCodigo: %d &quot;,(p+i)->codigo ); printf(&quot;\nNombre: &quot;); puts(  (p+i)->nombre  ); } } int main(int argc, char *argv[]) {  //array de estructuras struct datos  array[t]; //LLamada a las funciones LEER(array); IMPRIMIR(array); system(&quot;PAUSE&quot;); return 0; } #include <stdio.h> #include <stdlib.h> #define t 3 struct datos { int codigo; char nombre[15];  }; void LEER(struct datos *p) { printf(&quot;\n* * LEER VALORES EN LA ESTRUCTURA * *&quot;);  printf(&quot;\nIntroduce el codigo: &quot;); scanf(&quot;%d&quot;,  &p->codigo ); printf(&quot;Introduce el nombre: &quot;); fflush(stdin); gets(  p->nombre );  } void IMPRIMIR(struct datos *p) { printf(&quot;\n* * IMPRIMIR EL CONTENIDO DE LA ESTRUCTURA * *&quot;); printf(&quot;\nCodigo: %d“,  p->codigo ); printf(&quot;\nNombre: &quot;); puts(  p->nombre  ); } int main(int argc, char *argv[]) {  //Variable de estructuras struct datos  persona ; //LLamada a las funciones LEER(&persona); IMPRIMIR(&persona); system(&quot;PAUSE&quot;); return 0; } Pasar una  estructura  a  una funión Pasar un  array de estructuras  a una funión

Estructuras punteros

  • 1.
    #include <stdio.h> #include<stdlib.h> //* * ESTRUCTURAS * * //Declaramos la estructura struct datos { int codigo; char nombre[15]; }; int main(int argc, char *argv[]) { //Variable struct datos persona ; //PARA METER VALORES printf(&quot;Introduce el codigo:&quot;); scanf(&quot;%d&quot;, &persona.codigo ); fflush(stdin); printf(&quot;Introduce el nombre:&quot;); gets( persona.nombre ); system(&quot;PAUSE&quot;); return 0; } #include <stdio.h> #include <stdlib.h> //* * ESTRUCTURAS CON PUNTEROS * * //Declaramos la estructura struct datos { int codigo; char nombre[15]; }; int main(int argc, char *argv[]) { //Variable struct datos persona ; //Puntero struct datos * p ; //Inicializar puntero p = &per ; //PARA METER VALORES printf(&quot;Introduce el codigo:&quot;); scanf(&quot;%d&quot;, &p->codigo ); fflush(stdin); printf(&quot;Introduce el nombre:&quot;); gets( p->nombre ); system(&quot;PAUSE&quot;); return 0; }
  • 2.
    #include <stdio.h> #include<stdlib.h> //* *ARRAYS DE ESTRUCTURAS CON PUNTEROS * * //Declaramos la estructura struct datos { int codigo; char nombre[15]; }; int main(int argc, char *argv[]) { int i; struct datos array[3]; //Puntero struct datos *p ; //Inicializar puntero p = array ; //RECORRER ARRAY PARA METER VALORES for(i=0;i<3;i++) { printf(&quot;Introduce el codigo:&quot;); scanf(&quot;%d&quot;, &(p+i)->codigo ); fflush(stdin); printf(&quot;Introduce el nombre&quot;); gets( (p+i)->nombre ); } system(&quot;PAUSE&quot;); return 0; } #include <stdio.h> #include <stdlib.h> //* * ESTRUCTURAS CON PUNTEROS * * //Declaramos la estructura struct datos { int codigo; char nombre[15]; }; int main(int argc, char *argv[]) { struct datos per ; //Puntero struct datos *p ; //Inicializar puntero p =& per ; //PARA METER VALORES printf(&quot;Introduce el codigo:&quot;); scanf(&quot;%d&quot;, &p->codigo ); fflush(stdin); printf(&quot;Introduce el nombre:&quot;); gets( p->nombre ); system(&quot;PAUSE&quot;); return 0; }
  • 3.
    #include <stdio.h> #include<stdlib.h> #define t 3 struct datos { int codigo; char nombre[15]; }; void LEER(struct datos *p) { int i; printf(&quot;\n* * LEER VALORES EN LA ESTRUCTURA * *&quot;); for(i=0;i<t;i++) { printf(&quot;\nCodigo: &quot;); scanf(&quot;%d &quot;,&(p+i)->codigo ); printf(&quot;Nombre: &quot;); fflush(stdin); gets( (p+i)->nombre ); } } void IMPRIMIR(struct datos *p) { int i; printf(&quot;\n* * IMPRIMIR EL CONTENIDO DE LA ESTRUCTURA * *&quot;); for (i=0;i<t;i++) { printf(&quot;\nCodigo: %d &quot;,(p+i)->codigo ); printf(&quot;\nNombre: &quot;); puts( (p+i)->nombre ); } } int main(int argc, char *argv[]) { //array de estructuras struct datos array[t]; //LLamada a las funciones LEER(array); IMPRIMIR(array); system(&quot;PAUSE&quot;); return 0; } #include <stdio.h> #include <stdlib.h> #define t 3 struct datos { int codigo; char nombre[15]; }; void LEER(struct datos *p) { printf(&quot;\n* * LEER VALORES EN LA ESTRUCTURA * *&quot;); printf(&quot;\nIntroduce el codigo: &quot;); scanf(&quot;%d&quot;, &p->codigo ); printf(&quot;Introduce el nombre: &quot;); fflush(stdin); gets( p->nombre ); } void IMPRIMIR(struct datos *p) { printf(&quot;\n* * IMPRIMIR EL CONTENIDO DE LA ESTRUCTURA * *&quot;); printf(&quot;\nCodigo: %d“, p->codigo ); printf(&quot;\nNombre: &quot;); puts( p->nombre ); } int main(int argc, char *argv[]) { //Variable de estructuras struct datos persona ; //LLamada a las funciones LEER(&persona); IMPRIMIR(&persona); system(&quot;PAUSE&quot;); return 0; } Pasar una estructura a una funión Pasar un array de estructuras a una funión