Excuse me, surely it is something without much difficulty for you but I am just starting in this language, my mistake is something logical that surely I can not understand since I feel that all the arithmetic sentences are made correctly. Keep in mind that the code lacks some technical aspects such as prototypes of functions, this happens because the code is not yet finalized.
The code is as follows:
#include <stdio.h>
#include <stdlib.h>
#define elementos 3
struct clientes{
char nombres[30];
char apellidos[20];
char numero[10];
char edad;
};
struct clientes clientes1[elementos];
int main()
{
int opc=0;
do{
printf("MENU DE OPCIONES\n");
printf("1- Altas\n");
printf("2- Bajas\n");
printf("3- Modificacion\n");
printf("4- Salir\n");
scanf("%d", &opc);
while(opc<1 || opc>5){ //verifico si la opción ingresada esta en el rango
printf("Por favor ingrese un numero del 1 al 4\n");
scanf("%d", &opc);
}
switch(opc){
case 1:
system("cls");
altas();
system("pause");
system("cls");
break;
}
}while(opc!=4);
return 0;
}
void limpiar(){
system ("cls");
printf("la pantalla esta limpia\n");
}
void altas(){
int i;
for(i=0; i<elementos;
i++) //aca se encuentra el error
{
printf("ingrese el nombre del cliente ");fflush(stdout);
gets(clientes1[i].nombres);
printf("ingrese el apellido de su cliente "); fflush(stdout);
gets(clientes1[i].apellidos);
printf("Ingrese el numero de telefono de su cliente ");fflush(stdout);
gets(clientes1[i]. numero);
}
for(i=0;
i<elementos; i++){
printf("su nombre es %s \n", clientes1[i].nombres);
printf("su apellido es %s \n", clientes1[i].apellidos);
printf("su numero de telefono %s \n", clientes1[i].numero);
}
}
The output gives me the answer that when entering the option of discharges (1) it does not let me enter the first name but skips to the line of code to enter the last name, with the other iterations (two more in total) I have no problem, it only happens in the first iteration.