bendroide
04-08-2011, 04:34 PM
hola amigos dragonistas, necesito comentar este programa en c.
#include <stdio.h> //libreria sirve para printf y scanf
#include <stdlib.h> //librera obligatoria para malloc() y el free
#include <string.h> //cadenas
#include <conio.h> //hacer un pause para mostrar datos
struct agenda //se declara una estructura
{
/*miembros de la estructura*/
char nombre [50];
char telefono[25];
char email[50];
};
/* se delcara una estructura nodo*/
struct nodo{
struct agenda dato;
struct nodo *proximo;
} ;
struct nodo *nuevonodo(void);
int colavacia(struct nodo *);
struct nodo *creacola (struct nodo *, struct agenda);
void mostrar (struct nodo *);
void main()
{
struct nodo *pri=NULL, *ult=NULL;
struct agenda x;
printf ("ingrese nombre: ");
gets(x.nombre);
while (strcmp(x.nombre, "fin"))
{
printf ("ingrese telefono: ");
gets (x.telefono);
printf ("ingrese mail: ");
gets(x.email);
ult=creacola(ult,x);
if (pri==NULL) pri=ult; //si es la 1 pasada pongo en pri el valor del primer nodo
printf ("ingrese nombre: ");
gets(x.nombre);
}
if (colavacia(pri)==1)
{
printf ("No se ingresaron registros");getch();
}
else mostrar(pri);
}
struct nodo *nuevonodo()
{
struct nodo *p;
p=(struct nodo *)malloc(sizeof(struct nodo));
if(p==NULL)
{
printf ("memoria ram llena");
getch();
exit(0);
}
return p;
}
struct nodo *creacola(struct nodo *ult, struct agenda x)
{
struct nodo *p;
p=nuevonodo();
(*p).dato=x;
(*p).proximo=NULL;
if(ult!=NULL) (*ult).proximo=p; //si hay nodo anterior en prox pongo la direccion del nodo actual
return p;
}
int colavacia(struct nodo *pri)
{
if(pri==NULL) return 1;
else
return 0;
}
void mostrar (struct nodo *pri)
{
struct nodo *aux;
while(pri!=NULL)
{
printf("Nombre: %s - telefono: %s - Mail: %s \n",
pri->dato.nombre,pri->dato.telefono,pri->dato.email);
aux=pri;
pri=(*pri).proximo;
free(aux);
}
}
osea agregarle comentarios a cada linea de code,espero su ayuda
saludos cordiales
#include <stdio.h> //libreria sirve para printf y scanf
#include <stdlib.h> //librera obligatoria para malloc() y el free
#include <string.h> //cadenas
#include <conio.h> //hacer un pause para mostrar datos
struct agenda //se declara una estructura
{
/*miembros de la estructura*/
char nombre [50];
char telefono[25];
char email[50];
};
/* se delcara una estructura nodo*/
struct nodo{
struct agenda dato;
struct nodo *proximo;
} ;
struct nodo *nuevonodo(void);
int colavacia(struct nodo *);
struct nodo *creacola (struct nodo *, struct agenda);
void mostrar (struct nodo *);
void main()
{
struct nodo *pri=NULL, *ult=NULL;
struct agenda x;
printf ("ingrese nombre: ");
gets(x.nombre);
while (strcmp(x.nombre, "fin"))
{
printf ("ingrese telefono: ");
gets (x.telefono);
printf ("ingrese mail: ");
gets(x.email);
ult=creacola(ult,x);
if (pri==NULL) pri=ult; //si es la 1 pasada pongo en pri el valor del primer nodo
printf ("ingrese nombre: ");
gets(x.nombre);
}
if (colavacia(pri)==1)
{
printf ("No se ingresaron registros");getch();
}
else mostrar(pri);
}
struct nodo *nuevonodo()
{
struct nodo *p;
p=(struct nodo *)malloc(sizeof(struct nodo));
if(p==NULL)
{
printf ("memoria ram llena");
getch();
exit(0);
}
return p;
}
struct nodo *creacola(struct nodo *ult, struct agenda x)
{
struct nodo *p;
p=nuevonodo();
(*p).dato=x;
(*p).proximo=NULL;
if(ult!=NULL) (*ult).proximo=p; //si hay nodo anterior en prox pongo la direccion del nodo actual
return p;
}
int colavacia(struct nodo *pri)
{
if(pri==NULL) return 1;
else
return 0;
}
void mostrar (struct nodo *pri)
{
struct nodo *aux;
while(pri!=NULL)
{
printf("Nombre: %s - telefono: %s - Mail: %s \n",
pri->dato.nombre,pri->dato.telefono,pri->dato.email);
aux=pri;
pri=(*pri).proximo;
free(aux);
}
}
osea agregarle comentarios a cada linea de code,espero su ayuda
saludos cordiales