elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Re: Error en c que no puedo detectar.. en: 28 Abril 2011, 03:44 am
Ahhh muchachos, muchisimas gracias !!!!
me anduvo perfecto ahora!! un saludo y espero que los pueda ayudar  si necesitan algo !
2  Programación / Programación C/C++ / Error en c que no puedo detectar.. en: 27 Abril 2011, 03:58 am
Hola chicos buenas.. soy nuevo en el foro, en verdad no puedo detectar el error en este programa, el compilador tampoco, solo que se me produce algun tipo de saturacion en memoria en plena ejecucion creo.. no se de donde viene el problema, les dejo todo el codigo, es largo disculpen.. espero que me puedan ayudar..

Código:
[center][left][center]#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

typedef struct
{
    int d,m,a;
} t_fecha;

typedef struct
{
    char nyap[40];
    t_fecha fnac;
    int edad;
    char tel[15];
} t_datos;

char menu (const char [][40]);
char pedir_opcion (const char [][40],const char *msj);
void Cargar(void);
void Mostrar(void);
void Ordenar(void);
void Alta(t_datos*);
char Preguntar (const char*);
int Correcta (t_fecha,t_fecha);
int SonDigitos (char*);
long int feccmp (t_fecha,t_fecha);
int Edad (t_fecha,t_fecha);

int main (void)
{
    char op;
    const char opciones [][40] = {
                                   "CMOS",
                                   "Cargar archivo.",
                                   "Mostrar archivo.",
                                   "Ordenar archivo por fec de nac.",
                                   "Salir"
                                 } ;
    op=menu(opciones);

    while(op!='S')
    {
        switch(op)
        {
            case 'C': Cargar(); break;
            case 'M': Mostrar(); break;
            case 'O': Ordenar();
        }
        op=menu(opciones);
    }

    return 0;
}

char menu (const char m[][40])
{
    char op;

    op=pedir_opcion(m,"\nIngrese su opcion: ");
    while(!strchr(m[0],op))
        op=pedir_opcion(m,"\nMal ingreso de opcion. Ingrese nuevamente: ");

    return op;
}

char pedir_opcion (const char m[][40],const char *msj)
{
    char op;
    int i;

    printf("\nMenu:");
    for (i=0 ; i<strlen(m[0]) ; i++)
      printf("\n    %c  -   %s", m[0][i],m[i+1]);

    printf("%s",msj);
    fflush(stdin);
    fscanf(stdin,"%c",&op);

    return toupper(op);
}

void Cargar(void)
{
    FILE *pf;
    t_datos per;
    char res = 'S';

    pf = fopen ("C:\\Archivos.txt","w");

    while(res=='S')
    {
        Alta(&per);
        printf("%d|%s|%d/%d/%d|%s\n",per.edad,per.nyap,per.fnac.d,per.fnac.m,per.fnac.a,per.tel);
        fprintf(pf,"%d|%s|%d/%d/%d|%s\n",per.edad,per.nyap,per.fnac.d,per.fnac.m,per.fnac.a,per.tel);
        res = Preguntar ("\nOtro registro? S/N: ");
    }

    fclose(pf);
}

char Preguntar (const char *msj)
{
    char op;
    printf("%s");
    fflush(stdin);
    scanf("%c",&op);
    op=toupper(op);
    if (op != 'S' && op != 'N')
         Preguntar ("\nIngreso una opcion erronea. Otro registro ? S/N: ");
    return op;
}

void Alta(t_datos *per)
{
    t_fecha hoy = {26,4,2011} ;

    printf("\nIngrese los datos correctamente: ");

    printf("\nIngresa nombre y apellido: ");
    fflush(stdin);
    gets(per->nyap);
    printf("\nIngresa fecha de nacimiento: ");
    fflush(stdin);
    scanf("%d %d %d",&per->fnac.d,&per->fnac.m,&per->fnac.a);
    while(!Correcta(per->fnac,hoy))
    {
        printf("\nIngreso mal la fecha de nacimiento. Ingrese nuevamente: ");
        fflush(stdin);
        scanf("%d %d %d",&per->fnac.d,&per->fnac.m,&per->fnac.a);
    }
    per->edad = Edad(per->fnac,hoy);
    printf("\nIngresa numero de telefono: ");
    fflush(stdin);
    gets(per->tel);
    while(!SonDigitos(per->tel))
    {
        printf("\nIngreso mal el telefono. Ingrese nuevamente: ");
        fflush(stdin);
        gets(per->tel);
    }
}

int Correcta (t_fecha fec,t_fecha hoy)
{
     int dias_x_mes[] = {31,28,31,30,31,30,31,31,30,31,30,31} ;

     if (fec.m == 2) dias_x_mes[1]=29 ;

     if((fec.d < 0 || fec.d > dias_x_mes[fec.m-1]) || (fec.m <0 || fec.m>12) || feccmp(hoy,fec) < 0 ) return 0;
     return 1;
}


int SonDigitos (char *cad)
{
    int i;
    for (i=0; i<strlen(cad); i++)
        if(cad[i]!='-' && (cad[i]<48 || cad[i]>57)) return 0;
    return 1;
}

long int feccmp (t_fecha f1,t_fecha f2)
{
    long int fecha1=f1.a*10000+f1.m*100+f1.d;
    long int fecha2=f2.a*10000+f2.m*100+f2.d;
    return fecha1-fecha2;
}

int Edad (t_fecha fec,t_fecha hoy)
{
    int edad = hoy.a-fec.a;
    if(hoy.m<fec.m) edad--;
    if(hoy.m==fec.m && hoy.d<fec.d) edad--;
    return edad;
}

void Ordenar(void)
{
    // en construccion
    return;
}

void Mostrar(void)
{
    // en construccion
    return;
}[/center][/left][/center]
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines