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);
}
}