Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: m87 en 4 Junio 2010, 16:28 pm



Título: LISTA SIMPLE
Publicado por: m87 en 4 Junio 2010, 16:28 pm
HOLA,ESTOY TRATANDO DE HACER ALGO BASICO, NO ME SALE,RECIEN ESTOY APRENDIENDO, PORQUE ME PARACE Q EN EL BUCLE WHILE(RESP!='N')AL ULTIMO SALE LA PREG "DESEA...",PERO DEBAJO DE ESO YA APARECE "LU"....LE FALTA UN CORCHETE? Y TAMBIEN COMO HAGO PARA QUE MUESTRE LA LISTA?AYUDA.GRACIAS
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>


struct fecha
{
char dia,mes,año;
};
struct alumno
{
int lu;
long int dni;
char apellido[20];
char nombre[20];
char carrera[25];
int edad;
struct fecha ing;
struct alumno*sig;
};
void DarAlta();
void MostrarDatos();

void main ()

{
int op=0;
while (op!=3)
{

printf("====Menu====\n\n");
printf("1-Dar de Alta\n");
printf("2-Mostar Datos\n");
printf("3-Salir\n");
scanf("%d",&op);
switch(op)
{
case 1:DarAlta();break;
case 2:MostrarDatos();break;

}
}
}
void DarAlta ()
{
char resp='s';
while(resp!='n')
{
struct alumno*aux;
struct alumno*inicio=NULL;
struct alumno*nuevo=((struct alumno*)malloc(sizeof(struct alumno)));
printf("INGRESE LOS DATOS:\n");
printf("lu:\n");
scanf("%d",&nuevo->lu);
printf("DNI:\n");
scanf("%d",&nuevo->dni);
printf("Apellido:\n");
scanf("%s",nuevo->apellido);
printf("nombre:\n");
scanf("%s",nuevo->nombre);
printf("carrera:\n");
scanf("%s",nuevo->carrera);
printf("edad:\n");
scanf("%d",&nuevo->edad);
printf("fecha de ingreso:\n");
printf("dia\n");
scanf("%d",nuevo->ing.dia);
printf("mes:\n");
scanf("%d",nuevo->ing.mes);
printf("a¤o:\n");
scanf("%d",nuevo->ing.año);
nuevo->sig=NULL;
if (inicio==NULL)
{
inicio=nuevo;
}
else
aux=inicio;
if (aux->lu>nuevo->lu)
{
nuevo->sig=aux;
inicio=nuevo;
}
else
{
while (aux->sig!=NULL & nuevo->lu>=aux->sig->lu)
{
aux=aux->sig;
}
nuevo->sig=aux->sig;
aux->sig=nuevo;
}
printf("Desea ingresar mas datos\n");
scanf("%c",&resp);
}
}

void MostrarDatos ()
{
struct alumno*inicio;
struct alumno*aux;
int i;
i=0;
aux=inicio;
while (aux!=NULL)
{
printf("%d",aux->lu);
printf("%d",aux->dni);
printf("%s",aux->apellido);
printf("%s",aux->nombre);
printf("%s",aux->carrera);
printf("%d",aux->edad);
printf("%d",aux->ing.dia);
printf("%d",aux->ing.mes);
printf("%d",aux->ing.año);
aux=aux->sig;
i++;
}
if (i==0)
printf("La lista esta vacio");
}



Título: Re: LISTA SIMPLE
Publicado por: Littlehorse en 5 Junio 2010, 05:31 am
La verdad no te entendí demasiado sobre cual es el error, lo que si veo es que tu código tiene varios errores. Te remarco algunos:

Código
  1. #include <conio.h>

Librería no estándar, no la necesitas para nada.

Código
  1. void main ()

main siempre debe devolver un entero. int main().

En cuanto al resto, usa la etiqueta GeSHI para poner código, de esta forma:

[code=c]codigo[/code]


En cuanto a la idea general en la implementación de listas, te dejo este link (http://es.wikipedia.org/wiki/Lista_%28inform%C3%A1tica%29). Léelo entero, seguro te aclara el panorama.

Saludos!


Título: Re: LISTA SIMPLE
Publicado por: [D4N93R] en 5 Junio 2010, 05:41 am
Lilhorse como haces para poner las etiquetas GeSHI y que se vean? xD


Título: Re: LISTA SIMPLE
Publicado por: Littlehorse en 5 Junio 2010, 05:45 am
[nobbc][code=c]codigo[/code][/nobbc]
 ;D


Título: Re: LISTA SIMPLE
Publicado por: [D4N93R] en 5 Junio 2010, 05:48 am
Se me había olvidado!! gracias!! :D  ;-) ;-)