PDA

View Full Version : need help with this turboC sourcecode


asdf
July 17th, 2007, 04:01 PM
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<string.h>

FILE *status;
int ch;
char *dev_list[]={"idle","Tubelight","Fan","Nightlamp","Television","Aircooler","Refrigerator","Dvd Player","end"};
int day[]={0,2,4,6,0,1,3,5,7,0};
int night[]={0,1,2,3,5,6,7,0,4,0};
int out[]={0,3,0,1,2,4,5,6,7,0};
int reset[]={0,0,1,2,3,4,5,6,7,0};
int device[256];
int port=0x378;
void activte(int *ptr);
void switch_load(int);

main()
{
int disp_menu();
void disp_load();
void profiles();
void switching();
void load_status();
void exit_code();
int welcome();
int choice;
int hour;
status_file();
for(;;)
{
clrscr();
hour=welcome();
choice=disp_menu();
switch(choice)
{
case 1:disp_load();
printf("\n\n\n Press any key to continue...");
getch();
break;
case 2:profiles();
break;
case 3:switching();
break;
case 4:load_status();
break;
case 5:exit_code(hour);
default: printf("\n\n INVALID CHOICE");
printf("\n\n\n\n\n PRESS ANY KEY TO RETURN TO MAIN MENU............");
getch();
}
}
}
status_file()
{
int i=0;
status=fopen("status.txt","r");
if(status==NULL)
{
puts("Unable to open device status file");
exit(1);
}
while(1)
{
ch=fgetc(status);
if(i>=256)
break;
else
device=ch;
i++;
}
fclose(status);
return(0);
}
welcome()
{
struct time t;
struct date d;
clrscr();
printf("\n\n\t\t\t$$$POWER CONTROL USING P$$$\n\n\n");
gettime(&t);
getdate(&d);
printf("\n\nTIME:%2d:%2d",t.ti_hour,t.ti_min);
printf("\n\nDATE:%2d/0%d/%2d",d.da_day,d.da_mon,d.da_year);
if(t.ti_hour>=0x5&&t.ti_hour<0xb)
printf("\n\nGOOD MORNING...\n");
if(t.ti_hour>=0xb&&t.ti_hour<0x11)
printf("\n\nGOOD AFTERNOON...");
if(t.ti_hour>=0x11&&t.ti_hour<0x16)
printf("\n\nGOOD EVENING...");
return(t.ti_hour);
}
int disp_menu()
{
int choice;
printf("\n 1.LIST OF LOADS AND THEIR CODES");
printf("\n 2.STANDARD PROFILES (DAY/NIGHT)");
printf("\n 3.SWITCHING");
printf("\n 4.LOAD'S STATUS");
printf("\n 5.EXIT\n");
printf("\t\t\t\t ENTER YOUR CHOICE");
scanf("%d",&choice);
return(choice);
}
void disp_load()
{
int i;
clrscr();
printf("\n THE LIST OF LOADS WHICH CAN BE CONTROLLED ARE:\n\n");
for(i=1;strcmpi(&dev_list[i][0],"end");i++)
printf("\n\t%2d.%s",i,dev_list[i]);
return;
}
void profiles()
{
char p;
for(;;)
{
clrscr();
printf("\nSTANDARD PROFILES:\n");
printf("\n\n\t\t 1.DAY MODE");
printf("\n\t\t 2.NIGHT MODE");
printf("\n\t\t 3.OUT OF STATION");
printf("\n\t\t 4.RESET");
printf("\n\t\t 5.EXIT");
printf("\n\n\n\nENTER YOUR CHOICE:");
p=getchar();
switch(p)
{
case 'd':
case 'D':
case '1': activate(day);
return;
case 'n':
case 'N':
case '2': activate(night);
return;
case 'o':
case 'O':
case '3': activate(out);
return;
case 'r':
case 'R':
case '4': activate(reset);
return;
case 'e':
case 'E':
case '5': return;
}
}
}
[I]void activate(int *ptr)
{
int i;
char c;
printf("\n\nTHE FOLLOWING DEVICES WILL BE SWITCHED ON...\n");
for(i=1;ptr[i]!=0;i++)
printf("\n%d.%s",ptr[i],dev_list[ptr[i]]);
printf("\n\nTHE FOLLOWING DEVICES WILL BE SWITCHED OFF...\n");
for(i++;ptr[i]!=0;i++)
printf("\n%d.%s",ptr[i],dev_list[ptr[i]]);
printf("\n\nDO YOU WANT TO ACTIVATE THIS PROFILE...(y/n);");
c=getch();
printf("%c",c);
getch();
if(c=='y'||c=='Y')
{
for(i=1;ptr[i]!=0;i++);
if(device[ptr[i]]==0)
switch_load(ptr[i]);
for(i++;ptr[i]!=0;i++)
if(device[ptr[i]]==1)
switch_load(ptr[i]);
}
}


void switching()
{
int i,on_off;
disp_load();
printf("\n\n\n\nEnter the code of the device to be switched:");
scanf("%d",&i);
printf("OPTIONS:");
printf("\t 0--OFF\t 1--ON\n");
printf("\nENTER YOUR CHOICE:");
reenter:scanf("%d",&on_off);
if(on_off==1)
{
if(device[i]==1)
{
printf("\The Device is already ON");
getch();
}
else
switch_load(i);
}
else if(on_off==0)
{
if(device[i]==0)
{
printf("\nThe Devuce is already off,,,");
getch();
}
else
switch_load(i);
}
else
{
printf("Invalid Option\nPlease Re-Enter");
goto reenter;
}
}
void load_status()
{
int i;
clrscr();
printf("\n\nTHE FOLLOWING DEVICES ARE ON:\n");
for(i=1;strcmpi(&dev_list[i][0],"end");i++)
if(device[i]==1)
printf("\n%d.%s",i,dev_list[i]);
printf("\n\nTHE FOLLOWING DEVICES ARE OFF:\n");
for(i=1;strcmpi(&dev_list[i][0],"end");i++)
if(device[i]==0)
printf("\n%d.%s",i,dev_list[i]);
printf("\n\n\n\nPress any key to continue...");
getch();
}
void switch_load(int adrr)
{
if(device[adrr]==0)
{
device[adrr]=1;
outportb(port,adrr);
delay(50);
outportb(port,0x00);
}
else
{
device[adrr]=0;
outportb(port,adrr);
delay(50);
outportb(port,0x00);
}
}
void exit_code(int hour)
{
clrscr();
printf("\t\t\tTHANK YOU FOR USING THIS SOFTWARE\n");
if(hour>=0x13||hour<0x4)
printf("\n\n KONBANWA...\n");
file_update();
printf("\n\n\n\n\n\n\n\nPRESS ANY KEY TO EXIT...");
getch();
exit(0);
}
file_update()
{
int i=0;
status=fopen("status.txt","w+");
if(status==NULL)
{
puts("Unable to open device status file");
exit(1);
}
while(1)
{
ch=device[1];
if(i>=256)
break;
else
fputc(ch,status);
i++;
}
fclose(status);
return 0;
}

when i tried compiling the said sourcecode, the followng appears

"Type mismatch in redeclaration of "activate""

can anybody help me with this? i alrady highlighted the line where the error appears...

thanks so much....

z1p
July 17th, 2007, 04:52 PM
You have a typo in the declaration

void activte(int *ptr);