Ok, so Im in first year of programming and Im having some difficulties, We're only using math.h,stdlib.h, stdio.h libraries..
And we're doing a program which the user enters the clients.
In:
1
Jhonny Bravo
Front Ave. #21
1984-05-13
Out:
Clients number:1
Client Name: Jhonny Bravo
Adress: Front Ave. #21
DofBirth: 1984-05-13
...
..And so on..
Heres the Code
THe problem is that when Im using numbers or spaces the code wont wait for the user to input what is asked for next....
Heres the code:
Code:
#include <stdio.h>#include <string.h>
#include <stdlib.h>
typedef struct clientes
{
int numerocliente;
char nombre[30];
char nacimiento[15];
char direccion[30];
struct Clientes *psig;
struct Clientes *pant;
}CLIENTE;
int main(void)
{
struct clientes *pfirst =NULL;
struct clientes *pcurrent =NULL;
struct clientes *plast =NULL;
char temp[15];
int opcion=0;
for(;;)
{
printf("\n\n Elige:");
printf("\n 1. Agregar Empleado");
printf("\n 2. Eliminar");
printf("\n 3. Mostrar Info de Empleado");
printf("\n 4. Quit\n\n");
printf(" La decision esta en tus manos: ");
scanf("%d",&opcion);
switch(opcion)
{
case 1:
if((pcurrent=(CLIENTE *)malloc(sizeof(CLIENTE)) )==NULL)
{
fprintf(stderr,"No hay Memoria\n");
exit(1);
}
if (pfirst==NULL)
{
pfirst=pcurrent;
pcurrent->pant=NULL;
}
else
{
plast->psig=pcurrent;
pcurrent->pant=plast;
}
printf("\nDame el Numero de Cliente: \n");
scanf("%d", &pcurrent->numerocliente);
printf("Dame EL Nombre: \n");
scanf("%s",pcurrent->nombre);
printf("Dame la fecha de nacimiento(aaa-mm-dd): \n");
scanf("%s", temp);
strcpy(pcurrent->nacimiento,temp);
printf("Direccion del Cliente \n");
scanf("%s", pcurrent->direccion);
plast=pcurrent;
break;
case 2:
puts("Dame El Nombre a Eliminar: ");
scanf("%s", temp);
break;
case 3:
while(pcurrent != NULL)
{
printf("\n\nNombre del Cliente: %s\n Numero del Cliente: %d\n",pcurrent->nombre,pcurrent->numerocliente);
printf("\nFecha de Nacimiento del Cliente: %s\n, Direccion del Cliente: %s\n",pcurrent->nacimiento,pcurrent->direccion);
plast=pcurrent;
pcurrent=pcurrent->pant;
free(plast);
}break;
case 4: free(plast);
exit(1);
break;
}//end of switch
}//end of loop
return 0;
}
Any feedback is accepted, and I thank you for your time!