Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- struct producto{
- char nombre[100]; // 1 bytes * 100
- float precio; // 4 bytes
- struct {
- char nombre[60];
- float lat,lng;
- } origen;
- };
- void mostrarInformacionDelProducto(struct producto p){
- printf("Producto: %s proveniente de %s \n -> Precio : %f \n\n",
- p.nombre, p.origen.nombre, p.precio);
- }
- void asignarAProducto(struct producto *P,
- char *nombre, float precio,
- char *origen, float lat, float lng){
- strcpy(P->nombre , nombre);
- strcpy(P->origen.nombre , origen);
- P->precio = precio;
- P->origen.lat = lat;
- P->origen.lng = lng;
- }
- int main(){
- struct producto P[10];
- int i;
- float a,b,c;
- char str1[100], str2[100];
- printf("La estructura ocupa %d bytes en memoria.\n",
- sizeof(struct producto));
- // Como cargar 5 datos
- for (i = 0; i < 5; i++){
- printf("Producto %d", i);
- printf("\nIngrese el nombre del producto: ");
- scanf("%s", str1); fflush(stdin);
- printf("Ingrese el nombre del origen: ");
- scanf("%s", str2); fflush(stdin);
- printf("Ingrese el precio: ");
- scanf("%f", &a); fflush(stdin);
- printf("Ingrese la latitud: ");
- scanf("%f", &b); fflush(stdin);
- printf("Ingrese el longitud: ");
- scanf("%f", &c); fflush(stdin);
- printf("\n");
- asignarAProducto(&P[i], str1, a, str2, b, c);
- mostrarInformacionDelProducto(P[i]);
- }
- /*
- // Asignacion caso particular en el main
- strcpy(P[0].nombre , "Alfajor");
- strcpy(P[0].origen.nombre , "Arcor");
- P[0].precio = 19.99;
- P[0].origen.lat = 23.3;
- P[0].origen.lng = 42.3;
- // Asignacion caso particular a traves de la funcion
- asignarAProducto(&P[0], "Alfajor",19.99, "Arcor",
- 23.3, 42.3);
- // Mostrar elemento i=0
- mostrarInformacionDelProducto(P[0]);
- */
- return 0;
- }
- /*
- #include <stdio.h>
- #include <string.h>
- struct nombre{
- char cad[100];
- };
- int main(){
- int i=0;
- char *ptr;
- struct nombre A,*B, C[10];
- strcpy(A.cad, "Valentina");
- for (ptr = A.cad ;*ptr!=0;ptr++);
- printf("El nombre de A es %s y tiene %d caracteres \n",
- A.cad, (int)(ptr - A.cad));
- printf("")
- return 0;
- }
- */
- /*
- #include <stdio.h>
- void ImprimirCaracter(char caracter);
- void ImprimirCaracteres(char, int);
- void ImprimirFilas(char, int, int);
- void ImprimirCaracter(char caracter){
- printf("%c", caracter);
- }
- void ImprimirCaracteres(char c, int n){
- int i;
- if (c == 0) return;
- for (i = 0; i < n; i++)
- ImprimirCaracter(c);
- }
- void ImprimirFila(char caracter, int vecesEspacio,
- int vecesCaracter){
- ImprimirCaracteres(' ', vecesEspacio);
- ImprimirCaracteres(caracter, vecesCaracter);
- printf("\n");
- }
- void ImprimirPiramide(int F){
- int i;
- for(i = 0; i < F; i++)
- ImprimirFila('*', F-1-i, i+1);
- }
- int main(){
- ImprimirPiramide(40);
- return 0;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement