[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

problem with a c code



good evening

I have started working with geany a few days mostly because I was using Borland c++ 5.0 and that is because that is what my teachers use in college (I'm from venezuela), but the problem came when I was trying to capture strings with gets(), the program fails and I going to post in the message the code so you can see for yourself.

Note: if you don't understand spanish don't worry just input any string eventually you'll see the problem

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

void ingresar(struct persona emp[3]);
void comparar(struct persona emp[3]);

struct persona
{
    char nombre[30];
    char apellido[30];
    char cedula[14];
    double sueldo;
};//fin estructura persona

int main()
{
struct persona empleado[3];
    ingresar(empleado);
    system("clear");
    comparar(empleado);
    system("clear");
    return 0;
}//fin main

void ingresar(struct persona emp[3])
{

    for(int i=0;i<=2;i++)
    {
        cout<<"INGRESE LOS DATOS DEL EMPLEADO"<<endl<<endl;
        cout<<"Nombre: "; gets(emp[i].nombre); cout<<endl;
        cout<<"Apellido: "; gets(emp[i].apellido); cout<<endl;
        cout<<"Cedula: "; gets(emp[i].cedula); cout<<endl;
        cout<<"Sueldo: "; cin>>emp[i].sueldo; cout<<endl;
    }
}//fin funcion ingresar

void comparar(struct persona emp[3])
{
int j=1;

    for(int i=0; i<=2;i++)
    {
        if (emp[i].sueldo>emp[j].sueldo)
        {
            cout<<"El sueldo del empleado "<<emp[i].nombre<<" es mayor";
        }//fin if
    }//fin for

}//fin funcion comparar


Reply to: