Floating Point


 
Thread Tools Search this Thread
Top Forums Programming Floating Point
# 1  
Old 02-03-2011
Floating Point

Anyone help me i cant found the error of floating point
if needed, i added the code complete
HTML Code:
#include <stdio.h> 
#include <string.h> 
#include <stdlib.h> 
#include <ctype.h> 
 
typedef struct 
{ 
  int hh; 
  int mm; 
  int ss; 
  char nom[500]; 
  int punt; 
}cancion; 
 
typedef struct 
{ 
  int hh; 
  int mm; 
  int ss; 
  char name[100]; 
  int pref; 
  int segm; 
}shows; 
 
typedef struct 
{ 
  int ss; 
  char nomb[100]; 
  int vecs; 
}publicidad; 
 
typedef publicidad pub[100]; 
typedef shows sho[15];            //VECTORES DE REGISTROS 
typedef cancion mu[1000]; 
 
 
void VecCan(FILE *can,mu Mu,int *numcan);        //PROCEDIMIENTOS 
void VecSho(FILE *SHOW,sho Sho,int *numshow); 
void VecPub(FILE *publi,pub Pub); 
void impg(FILE *grilla,int HH,int MM,int SS,char tipo[],int band,mu Mu,sho Sho,pub Pub,int rancan,int ransho,int ranpub); 
void Time(int *horas,int *minutos,int *segundos); 
 
int main()        //INICIO 
{ 
        //DECLACION DE ARCHIVOS 
 
        FILE *can, *publi, *SHOW, *grilla; 
 
        int op = 0; 
        int regact = 0; 
        char pausa; 
        int numcan,numshow,numpub; 
        int i,band,cant,rancan,ransho,ranpub,acum,repite; 
        char tipo[2]; 
        char C,S,P; 
        int HH=0,MM=5,SS=0; 
 
        //ABRIENDO ARCHIVOS 
 
        can=fopen("canciones.in","r"); 
        publi=fopen("publicidad.in","r"); 
        SHOW=fopen("shows.in","r"); 
        grilla=fopen("Grilla.out","w"); 
 
 
 
        mu Mu; 
        sho Sho; 
        pub Pub; 
 
 
 
        while (op != 6)   //INICIO DEL MENU 
        { 
 
              system("clear"); 
              printf("Menu Principal\n"); 
              printf("~~~~~~~~~~~~~~\n"); 
              printf("1.- Musica Disponible\n"); 
              printf("2.- Publicidad Disponible\n"); 
              printf("3.- Shows Diarios\n"); 
              printf("4.- Programacion del Dia\n"); 
              printf("5.- Busqueda\n"); 
              printf("6.- Salir\n\n"); 
              op = 0; 
                    while ((op < 1) || (op > 6)) 
                    { 
                     printf("Seleccione su Opcion (1-6): "); 
                     scanf("%d",&op); 
                    } 
                switch(op) 
                { 
                        case 1: system("clear"); 
                                if(can==NULL) 
                                { 
                                    printf("No Abrio el Archivo"); 
                                } 
                                else 
                                { 
                                    while(!feof(can)) 
                                    { 
                                        regact=fgetc(can); 
                                        printf("%c",regact); 
                                    } 
                                     
                                } 
                                printf("\nPulse Enter para continuar..."); 
                                scanf("%2c",&pausa); 
                        break; 
 
                        case 2: system("clear"); 
                                if(publi==NULL) 
                                { 
                                    printf("No Abrio el Archivo"); 
                                } 
                                else 
                                { 
                                    while(!feof(publi)) 
                                    { 
                                        regact=fgetc(publi); 
                                        printf("%c",regact); 
                                    } 
                                     
                                } 
                                printf("\nPulse Enter para continuar..."); 
                                scanf("%2c",&pausa); 
                        break; 
 
                        case 3: system ("clear"); 
                                if(SHOW==NULL) 
                                { 
                                    printf("No Abrio el Archivo"); 
                                } 
                                else 
                                { 
                                    while(!feof(SHOW)) 
                                    { 
                                        regact=fgetc(SHOW); 
                                        printf("%c",regact); 
                                    } 
                                     
                                } 
                                printf("\nPulse Enter para continuar..."); 
                                scanf("%2c",&pausa); 
                        break; 
 
                        case 4: system("clear"); 
                                        if(can==NULL)       //VALIDACION DE ARCHIVO CANCIONES 
                                        { 
                                            printf("No Abrio el Archivo"); 
                                        } 
                                        else 
                                        { 
                                            while(!feof(can)) 
                                        { 
                                            VecCan(can,Mu,&numcan); 
                                        } 
                                         
                                        } 
 
                                        if(SHOW==NULL)      //VALIDACION DE ARCHIVO SHOW 
                                        { 
                                            printf("No Abrio el Archivo"); 
                                        } 
                                        else 
                                        { 
                                        while(!feof(SHOW)) 
                                        { 
                                            VecSho(SHOW,Sho,&numshow); 
                                        } 
                                         
                                        } 
 
                                        if(publi==NULL)     //VALIDACION DE ARCHIVO PUBLICIDAD 
                                        { 
                                            printf("No Abrio el Archivo"); 
                                        } 
                                        else 
                                        { 
                                                 
                                            numpub=0; 
                                            i=i+1; 
                                            while(!feof(publi)) 
                                            { 
                                                   
 
                                                            //LECTURA DE PUBLICIDAD 
                                                        fscanf(publi,"%[^0-9] ",Pub[i].nomb); 
                                                        fscanf(publi,"%d ",&Pub[i].ss); 
                                                        fscanf(publi,"%d ",&Pub[i].vecs); 
                                                    Pub[i].ss=Pub[i].ss+1; 
                                                    numpub++;//VARIABLE FUSION 
                                                    i++; 
                                                    printf("%s %d %d %d\n",Pub[i].nomb,Pub[i].ss,Pub[i].vecs,numpub); 
                                             
                                            } 
                                        
                                       
                                        } 
                                                 
 
                                                        tipo[0]=C; 
                                                        tipo[1]=S; 
                                                        tipo[2]=P; 
                                                        //HORARIO DE LA GRILLA 
                                                            while(HH<=23) 
                                                            { 
 
                                                                band=rand()%2; 
                                                                 
                                                                if((HH>=7&&HH<=9)||(HH>=12&&HH<=14)||(HH>=18&&HH<=19)) 
                                                                { 
                                                                    if(band==0) 
                                                                    { 
                                                                        cant=1000; 
                                                                    do 
                                                                    { 
                                                                        rancan=rand()%numcan; 
                                                                        if((Mu[rancan].punt>=70)&&(rancan!=cant)) 
                                                                        { 
                                                                        impg(grilla,HH,MM,SS,tipo,band,Mu,Sho,Pub,rancan,ransho,ranpub); 
                                                                        Time(&HH,&MM,&SS); 
                                                                        HH=acum+HH; 
                                                                        repite=1; 
                                                                        cant=rancan; 
                                                                        } 
                                                                        else 
                                                                        { 
                                                                        repite=0; 
                                                                        } 
                                                                    }while(repite==0); 
 
                                                                    } 
 
                                                                    if(band==1) 
                                                                    { 
 
                                                                    do 
                                                                    { 
                                                                        ransho=rand()%numshow; 
                                                                        if((Sho[ransho].pref>=1)&&(Sho[ransho].segm!=0)) 
                                                                        { 
                                                                        Sho[ransho].segm=Sho[ransho].segm-1; 
                                                                        impg(grilla,HH,MM,SS,tipo,band,Mu,Sho,Pub,rancan,ransho,ranpub); 
                                                                        Time(&HH,&MM,&SS); 
                                                                        HH=acum+HH; 
 
                                                                        } 
 
 
                                                                    else 
                                                                    { 
                                                                    repite=0; 
                                                                    } 
                                                                    }while(repite==0); 
 
                                                                    } 
 
                                                                    if(band==2) 
                                                                    { 
 
                                                                    do 
                                                                    { 
                                                                        ranpub=rand()%numpub; 
                                                                        if(Pub[ranpub].vecs!=0) 
                                                                        { 
                                                                        Pub[ranpub].vecs=Pub[ranpub].vecs-1; 
                                                                        impg(grilla,HH,MM,SS,tipo,band,Mu,Sho,Pub,rancan,ransho,ranpub); 
                                                                        Time(&HH,&MM,&SS); 
                                                                        HH=acum+HH; 
                                                                        repite=1; 
                                                                        } 
                                                                        else 
                                                                        { 
                                                                        repite=0; 
                                                                        } 
                                                                    }while(repite==0); 
                                                                    } 
 
                                                                } 
                                                                else 
                                                                { 
                                                                     cant=1000; 
                                                                    rancan=rand()%numcan; 
                                                                    impg(grilla,HH,MM,SS,tipo,band,Mu,Sho,Pub,rancan,ransho,ranpub); 
                                                                    Time(&HH,&MM,&SS); 
                                                                    HH=acum+HH; 
                                                                    repite=1; 
                                                                    cant=rancan; 
 
 
                                                                    do 
                                                                    { 
                                                                        ranpub=rand()%numpub; 
                                                                        if(Pub[ranpub].vecs!=0) 
                                                                        { 
                                                                        Pub[ranpub].vecs=Pub[ranpub].vecs-1; 
                                                                        impg(grilla,HH,MM,SS,tipo,band,Mu,Sho,Pub,rancan,ransho,ranpub); 
                                                                        Time(&HH,&MM,&SS); 
                                                                        HH=acum+HH; 
                                                                        repite=1; 
                                                                        } 
                                                                        else 
                                                                        { 
                                                                        repite=0; 
                                                                        } 
                                                                    }while(repite==0); 
                                                                } 
                                                                printf("algo"); 
                                                            } 
                                    printf("\nPulse Enter para continuar..."); 
                                    scanf("%2c",&pausa); 
                            break; 
                        case 5: system("clear"); 
 
 
                            break; 
 
                } //FIN DE MENU 
        } 
 
return 0; 
}            //FIN DE MAIN 
 
//PROCEDIMIENTO DE LECTURA DE CANCIONES 
void VecCan(FILE *can,mu Mu,int *numcan) 
{ 
 
    int n,h; 
 
    fscanf(can,"%d",&n); //LEE LA CANTIDAD DE CANCIONES 
 
 
        for(h=0; h<n; h++) 
        { 
        fscanf(can,"%[^0-9] ",Mu[h].nom); 
        fscanf(can,"%d",&Mu[h].mm); 
        fscanf(can,"%d",&Mu[h].ss); 
        fscanf(can,"%d\n",&Mu[h].punt); 
        Mu[h].ss++; //INCREMENTANDO LOS SEGUNDOS 
        //printf("%s %d %d %d\n",Mu[h].nom,Mu[h].mm,Mu[h].ss,Mu[h].punt); 
        } 
        *numcan=n; 
} 
 
//PROCEDIMIENTO DE LECTURA DE SHOW 
void VecSho(FILE *SHOW,sho Sho,int *numshow) 
{ 
 
    int n,f; 
 
    fscanf(SHOW,"%d",&n); //LEE LA CANTIDAD DE SHOWS 
 
        for(f=0; f<n; f++) 
        { 
        fscanf(SHOW,"%[^0-9] ",Sho[f].name); 
        fscanf(SHOW,"%d",&Sho[f].mm); 
        fscanf(SHOW,"%d",&Sho[f].ss); 
        fscanf(SHOW,"%d",&Sho[f].segm); 
        fscanf(SHOW,"%d\n",&Sho[f].pref); 
        Sho[f].ss++; //INCREMENTANDO LOS SEGUNDOS 
        //printf("%s %d %d %d %d\n",Sho[f].name,Sho[f].mm,Sho[f].ss,Sho[f].segm,Sho[f].pref); 
        } 
        *numshow=n; 
} 
 
void Time(int *horas,int *minutos,int *segundos)// PROCEDIMIENTO DE TIEMPO 
{ 
 
    int j,m; 
 
        m=(*horas*3600)+(*minutos*60)+(*segundos); 
            for(j=0;j<m;j++) 
 
            (*segundos)++; 
            if(*segundos==60) 
            { 
            (*minutos)++; 
            *segundos=0; 
            } 
            if(*minutos==60) 
            { 
            (*horas)++; 
            *minutos=0; 
            } 
                if(*horas==24) 
                { 
                *horas=0; 
                } 
} 
 
 
void impg(FILE *grilla,int HH,int MM,int SS,char tipo[],int band,mu Mu,sho Sho,pub Pub,int rancan,int ransho,int ranpub) 
{ 
 
 
    fprintf(grilla, "%.2d\t%.2d\t%.2d\t ", HH, MM, SS); 
    fprintf(grilla, "%c\t",tipo[band]); 
 
    if(band==0) 
    { 
    fprintf(grilla, "%s\n",Mu[rancan].nom); 
    } 
 
    if(band==1) 
    { 
    fprintf(grilla, "%s\n",Sho[ransho].name); 
    } 
 
    if(band==2) 
    { 
    fprintf(grilla, "%s\n",Pub[ranpub].nomb); 
    } 
} 
 
# 2  
Old 02-03-2011
You have an unterminated (inifinite) loop (do { ... } ).

What error are you getting, EXACTLY?

Last edited by jim mcnamara; 02-03-2011 at 11:34 AM..
# 3  
Old 02-04-2011
the only error that is floating point
# 4  
Old 02-04-2011
No. Generate the error, then copy & paste the error so we can see it. I do not see something that says 'floating point error'
# 5  
Old 02-04-2011
Image

here!!

---------- Post updated at 03:10 PM ---------- Previous update was at 03:05 PM ----------

here error

=/Menu Principal
~~~~~~~~~~~~~~
1.- Musica Disponible
2.- Publicidad Disponible
3.- Shows Diarios
4.- Programacion del Dia
5.- Busqueda
6.- Salir

Seleccione su Opcion (1-6): 4

Excepción de coma flotante
# 6  
Old 02-04-2011
Your program reads some data into integers from publicidad.in.

Check publicidad.in to make sure you aren't reading a floating point value into an integer.
# 7  
Old 02-04-2011
I think I see why. You forgot to initialize these:

Code:
FILE *can, *publi, *SHOW, *grilla;

When you do that they don't necessarily start as NULL, you have to

Code:
FILE *can=NULL, *publi=NULL, *SHOW=NULL, *grilla=NULL;

Garbage in pointers can cause strange exceptions.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Arithmetic in floating point

is it not possible to simply di aritmetic without using bc or awk i have tried folllowing operatrions but they support only integer types plz suggest me code for floating using values stored in the variables.the ans i get is integer and if i input floating values i get error numeric constant... (6 Replies)
Discussion started by: sumit the cool
6 Replies

2. Shell Programming and Scripting

floating point numbers in if

# if > then > echo "1" > else > echo "2" > fi -bash: How can i compare floating point numbers inside statement? (15 Replies)
Discussion started by: proactiveaditya
15 Replies

3. Programming

Floating point Emulator

what is floating point emulator(FPE)? where and why it is used? (1 Reply)
Discussion started by: pgmfourms
1 Replies

4. Linux

Floating Point Exception

Hi, I am compiling "HelloWorld" C progam on 32-bit CentOS and i want to execute it on 64-bit CentOS architecture. For that i copied the a.out file from 32-bit to 64-bit machine, but while executing a.out file on 64bit machine I am getting "Floating point exception error". But we can run... (3 Replies)
Discussion started by: Mandar123
3 Replies

5. Linux

Floating point exception !!!

Hi, I have linux fedora 4 ver., 2.6 kernal. And qmail & mysql & samba servers are already configured on this server. When I try to install any package like squidguard ,dansguardian,webmin,rsnapshots with command rpm -ivh . It is giving error as “Floating point exception" Snap View is... (3 Replies)
Discussion started by: ssk01
3 Replies

6. Programming

Floating point error in C

Hi, see the simple code below double i; i=8080.9940; printf(" val :%.30f\n",i); output i m getting is val :8080.993999999999700000000000000 when i m expecting val :8080.9940 what happens?how can i avoid it? thanks... (2 Replies)
Discussion started by: Hara
2 Replies

7. Shell Programming and Scripting

Rounding off the value of Floating point value

Hello, i have some variables say: x=1.4 y=3.7 I wish to round off these values to : x = 2 (after rounding off) y = 4 (after rounding off) I am stuck. Please help. (7 Replies)
Discussion started by: damansingh
7 Replies

8. Programming

floating point problem

Hi all! Hi all! I am working with a problem to find the smallest floating point number that can be represented. I am going in a loop ,stating with an initial value of 1.0 and then diving it by 10 each time thru the loop. So the first time I am getting o.1 which I wanted.But from the next... (4 Replies)
Discussion started by: vijlak
4 Replies

9. Shell Programming and Scripting

floating point addition

hi, :) I have a file like this 10.456 123.567 456.876 234.987 ........ ....... What i want to do is ia have to add all those numbers and put the result in some other file. Any help pls. cheers RRK (8 Replies)
Discussion started by: ravi raj kumar
8 Replies

10. Shell Programming and Scripting

Floating Point Division

Does anyone have a simple way of doing floating point ("fp") division? For example, if I divide 3 by 5, I can get 0.6. The built-in calc (`bc`) will perform fp multiplication, but not division, at least not straight-up (i.e., starting bc and just typing in 3/5). I am trying to do this using... (1 Reply)
Discussion started by: gsatch
1 Replies
Login or Register to Ask a Question