 |
amisauv's Blog |
1
by amisauv on Tue 9th Dec 11am
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<ctype.h>
/****************************************************************
Functions prototype.
*****************************************************************/
void Open_File();
void Demage_Lexeme();
int Search(char[256],int);
void analyze();
void Skip_Comment();
void Read_String();
void Is_Keyword_Or_Not();
void Is_Identifier_Or_Not();
void Is_Operator_Or_Not();
void Read_Number();
void Is_Special_Or_Not();
void Is_Comparison_Or_Not();
void Add_To_Lexical (char[256],int,char[256]);
void Print_ST();
void Print_TOKEN();
void Token_Attribute();
/****************************************************************
Data structure used in program.
*****************************************************************/
struct lexical
{
char data[256]; //Value of token.
int line[256]; //Line # which token appear in input
file.
int times; //# of times that token appear in input
file.
char type[256]; //Type of each token.
struct lexical *next;
};
typedef struct lexical Lex;
typedef Lex *lex;
/****************************************************************
File pointer for accessing the file.
*****************************************************************/
FILE *fp;
FILE *st;
FILE *token;
char lexeme[256],ch;
int f,flag,line=1,i=1;
lex head=NULL,tail=NULL;
/****************************************************************
Array holding all keywords for checking.
*****************************************************************/
char
*keywords[]={"procedure","is","begin",&qu ot;end","var","cin","cout","if" ;,
"then","else","and","or","not& quot;,"loop","exit","when",
"while","until"};
/****************************************************************
Array holding all arithmetic operations for checking.
*****************************************************************/
char arithmetic_operator[]={'+','-','*','/'};
/****************************************************************
Array holding all comparison operations for checking.
*****************************************************************/
char *comparison_operator[]={"<",">","=",&qu ot;<=","<>",">="};
/****************************************************************
Array holding all special for checking.
*****************************************************************/
char special[]={'%','!','@','~','$'};
/****************************************************************
**************
*MAIN PROGRAM*
**************
*****************************************************************/
void main()
{
Open_File();
analyze();
fclose(fp);
Print_ST();
Print_TOKEN();
}
/****************************************************************
This function open input sourse file.
*****************************************************************/
void Open_File()
{
fp=fopen("source.txt","r"); //provide path for source.txt here
if(fp==NULL)
{
printf("!!!Can't open input file - source.txt!!!");
getch();
exit(0);
}
}
/****************************************************************
Function to add item to structure of array to store data and
information of lexical items.
*****************************************************************/
void Add_To_Lexical (char value[256],int line,char type[256])
{
lex new_lex;
if (!Search(value,line)) //When return 1 the token not found.
{
new_lex=malloc(sizeof(Lex));
if (new_lex!=NULL)
{
strcpy(new_lex->data,value);
new_lex->line[0]=line;
new_lex->times=1;
strcpy(new_lex->type,type);
new_lex->next=NULL;
if (head==NULL)
head=new_lex;
else
tail->next=new_lex;
tail=new_lex;
}
}
}
/****************************************************************
Function to search token.
*****************************************************************/
int Search (char value[256],int line)
{
lex x=head;
int flag=0;
while (x->next!=NULL && !flag)
{
if (strcmp(x->data,value)==0)
{
x->line[x->times]=line;
x->times++;
flag=1;
}
x=x->next;
}
return flag;
}
/****************************************************************
Function to print the ST.TXT .
*****************************************************************/
void Print_ST()
{
lex x=head;
int j;
if ((st=fopen("ST.TXT","w"))==NULL)
printf("The file ST.TXT cat not open.
");
else
{
fprintf(st," %s %s %s
","Line#","Lexeme","Type");
fprintf(st," ---- ------ ----
");
while (x!=NULL)
{
if ((strcmp(x->type,"num")==0) ||
(strcmp(x->type,"keyword")==0) ||
(strcmp(x->type,"identifier")==0))
{
fprintf(st," ");
for (j=0;j<x->times;j++)
{
fprintf(st,"%d",x->line[j]);
if (j!=x->times-1) //This condition to prevent the comma
fprintf(st,",",x->line[j]); //"," to not print after last line #.
}
fprintf(st," %-6s %-6s
",x->data,x->type);
}
x=x->next;
}
fclose(st);
}
}
/****************************************************************
Function to print the TOKENS.TXT .
*****************************************************************/
void Print_TOKEN()
{
int flag=0;
fp=fopen("source.txt","r");
if(fp==NULL)
{
printf("!!!Can't open input file - source.txt!!!");
getch();
exit(0);
}
else
{
if ((token=fopen("TOKENS.TXT","w"))==NULL)
printf("The file ST.TXT cat not open.
");
else
{
ch=fgetc(fp);
while (!(feof(fp)))
{
if (ch==' ' && !flag)
{
do
ch=fgetc(fp);
while (ch==' ');
fseek(fp,-2,1);
ch=fgetc(fp);
flag=1;
}
if (ch!='
' && ch!=' ')
fprintf(token,"%c",ch);
if (ch=='
')
{
fprintf(token,"
");
Token_Attribute();
i++;
flag=0;
}
ch=fgetc(fp);
}
}
}
fclose(fp);
fclose(token);
}
/****************************************************************
Function to put the token and atrribute in TOKENS.TXT .
*****************************************************************/
void Token_Attribute()
{
lex x=head;
int j;
while (x!=NULL)
{
if (x->line[0]==i)
{
fprintf(token,"token : %-4s ",x->type);
if ((strcmp(x->type,"num")==0) ||
(strcmp(x->type,"keyword")==0) ||
(strcmp(x->type,"identifier")==0))
{
fprintf(token,"attribute : line#=%-4d
",i);
}
else
{
fprintf(token,"attribute : %-4s
",x->data);
}
}
x=x->next;
}
fprintf(token,"
");
}
/****************************************************************
Function to create lexical analysis.
*****************************************************************/
void analyze()
{
ch=fgetc(fp); //Read character.
while(!feof(fp)) //While the file is not end.
{
if(ch=='
') //Compute # of lines in source.txt
.
{
line++;
ch=fgetc(fp);
}
if(isspace(ch) && ch=='
' )
{
line++;
ch=fgetc(fp);
}
if(isspace(ch) && ch!='
' ) //The character is space.
ch=fgetc(fp);
if(ch=='/' || ch=='"') //Function for skipping comments in the
file
Skip_Comment(); //and '"' with display statements.
if(isalpha(ch)) //The character is leter.
{
Read_String();
Is_Keyword_Or_Not();
Is_Operator_Or_Not();
Is_Identifier_Or_Not();
}
if(isdigit(ch)) //The character is digit.
Read_Number();
if (ch==';') //The character is semicolon.
Add_To_Lexical(";",line,"semicolon");
if (ch==':') //The character is colon.
Add_To_Lexical(":",line,"colon");
if (ch==',') //The character is comma.
Add_To_Lexical(",",line,"comma");
if (ch=='(') //The character is parenthesis.
Add_To_Lexical("(",line,"parenthesis");
if (ch==')') //The character is parenthesis.
Add_To_Lexical(")",line,"parenthesis");
//The character is comparison_operator
if (ch=='<' || ch=='=' || ch=='>')
Is_Comparison_Or_Not();
Is_Special_Or_Not(); //After failed scaning in before cases
//check the character is special or not.
Demage_Lexeme();
if(isspace(ch) && ch=='
' )
{
line++;
ch=fgetc(fp);
}
else
ch=fgetc(fp);
}
}
/****************************************************************
This function read all character of strings.
*****************************************************************/
void Read_String()
{
int j=0;
do
{
lexeme[j++]=ch;
ch=fgetc(fp);
} while(isalpha(ch));
fseek(fp,-1,1);
lexeme[j]='
by amisauv on Tue 9th Dec 10am
this code access the lpt port.here only 4 of the total 8 pins are used but can be modified for full 8 pins.it has a complete GUI with mouse & keyboard interactive control panel.works well in win98, but not in winxp.
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
#include<stdlib.h>
#include<bios.h>
#define port 0x0378
char ch;
void display(int,int,int,int);
void dispbutton(int);
void click(int,int,int,int);
void status(int,int,int,int);
void reset(int*,int*,int*,int*);
int x,y,button;
union REGS i,o;
initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}
void showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
}
void getmousepos(int *button, int *x,int *y)
{
i.x.ax =3;
int86(0x33,&i,&o);
*button =o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}
void hidemouseptr()
{
i.x.ax=2;
int86(0x33,&i,&o);
}
void main()
{clrscr();
int s1=0,s2=0,s3=0,s4=0;
int gdriver=DETECT,gmode,ercode;
initgraph(&gdriver,&gmode,"");
ercode=graphresult();
if(ercode!=0){printf("error code:%s",grapherrormsg(ercode));
getch();}
display(s1,s2,s3,s4);
initmouse();showmouseptr();
while(ch!=27)
{getmousepos(&button,&x,&y);
if(button==1)
{if(x>80&&x<180&&y>100&&y<140)ch='1';
if(x>200&&x<300&&y>100&&y<140)ch='2';
if(x>320&&x<420&&y>100&&y<140)ch='3';
if(x>440&&x<540&&y>100&&y<140)ch='4';
if(x>440&&x<540&&y>300&&y<340)ch=32;
if(x>80&&x<180&&y>300&&y<340)ch=27;
}
if(kbhit())ch=getch();
switch(ch)
{case '1':{s1=!s1;
click(s1,s2,s3,s4);
outportb(port,1);delay(500);outport(port,0);
ch='0';break;
}
case '2':{s2=!s2;
click(s1,s2,s3,s4);
outportb(port,2);delay(500);outport(port,0);
ch='0';break;
}
case '3':{s3=!s3;
click(s1,s2,s3,s4);
outportb(port,4);delay(500);outport(port,0);
ch='0';break;
}
case '4':{s4=!s4;
click(s1,s2,s3,s4);
outportb(port,8);delay(500);outport(port,0);
ch='0';break;
}
case 32:{click(s1,s2,s3,s4);
reset(&s1,&s2,&s3,&s4);
ch='0';break;
}
case 27: {click(s1,s2,s3,s4);
reset(&s1,&s2,&s3,&s4);
closegraph();exit(0);}
}
}
}
void display(int s1,int s2,int s3,int s4)
{setbkcolor(9);setcolor(1);
rectangle(5,5,635,475);rectangle(10,10,630,470);
dispbutton(1);dispbutton(2);dispbutton(3);dispbutton(4);
dispbutton(5);dispbutton(6);
status(s1,s2,s3,s4);
setcolor(1);
outtextxy(100,115,"SWITCH 1");
outtextxy(220,115,"SWITCH 2");
outtextxy(340,115,"SWITCH 3");
outtextxy(460,115,"SWITCH 4");
outtextxy(115,315,"EXIT");
outtextxy(470,315,"RESET");
}
void dispbutton(int n)
{int x1,y1,x2,y2;
if(n==1){x1=80;y1=100;x2=180;y2=140;}
if(n==2){x1=200;y1=100;x2=300;y2=140;}
if(n==3){x1=320;y1=100;x2=420;y2=140;}
if(n==4){x1=440;y1=100;x2=540;y2=140;}
if(n==5){x1=80;y1=300;x2=180;y2=340;}
if(n==6){x1=440;y1=300;x2=540;y2=340;}
setfillstyle(SOLID_FILL,7);
bar(x1,y1,x2,y2);
setcolor(15);
line(x1,y1,x2,y1);line(x1,y1,x1,y2);
setcolor(8);
line(x2,y1,x2,y2);line(x1,y2,x2,y2);
}
void click(int s1,int s2,int s3,int s4)
{int x1,y1,x2,y2;
if(ch=='1'){x1=80;y1=100;x2=180;y2=140;}
if(ch=='2'){x1=200;y1=100;x2=300;y2=140;}
if(ch=='3'){x1=320;y1=100;x2=420;y2=140;}
if(ch=='4'){x1=440;y1=100;x2=540;y2=140;}
if(ch==27){x1=80;y1=300;x2=180;y2=340;}
if(ch==32){x1=440;y1=300;x2=540;y2=340;}
hidemouseptr();
setcolor(15);line(x2,y1,x2,y2);line(x1,y2,x2,y2);
setcolor(8);line(x1,y1,x2,y1);line(x1,y1,x1,y2);
sound(50);delay(75);nosound();
setcolor(15);line(x1,y1,x2,y1);line(x1,y1,x1,y2);
setcolor(8);line(x2,y1,x2,y2);line(x1,y2,x2,y2);
showmouseptr();
status(s1,s2,s3,s4);
}
void status(int s1,int s2,int s3,int s4)
{setcolor(4);setfillstyle(SOLID_FILL,4);
circle(130,200,10);
circle(250,200,10);
circle(370,200,10);
circle(490,200,10);
if(s1==1)floodfill(130,200,4);
else {setcolor(0);setfillstyle(SOLID_FILL,0);circle(130,200,10);
floodfill(130,200,0);
setcolor(4);circle(130,200,10);setfillstyle(SOLID_FILL,4);
}
if(s2==1)floodfill(250,200,4);
else {setcolor(0);setfillstyle(SOLID_FILL,0);circle(250,200,10);
floodfill(250,200,0);
setcolor(4);circle(250,200,10);setfillstyle(SOLID_FILL,4);
}
if(s3==1)floodfill(370,200,4);
else {setcolor(0);setfillstyle(SOLID_FILL,0);circle(370,200,10);
floodfill(370,200,0);
setcolor(4);circle(370,200,10);setfillstyle(SOLID_FILL,4);
}
if(s4==1)floodfill(490,200,4);
else {setcolor(0);setfillstyle(SOLID_FILL,0);circle(490,200,10);
floodfill(490,200,0);
setcolor(4);circle(490,200,10);
}
}
void reset(int *s1,int *s2,int *s3,int *s4)
{if(*s1==1)
{outportb(port,1);delay(500);outport(port,0);}
if(*s2==1)
{outportb(port,2);delay(500);outport(port,0);}
if(*s3==1)
{outportb(port,4);delay(500);outport(port,0);}
if(*s4==1)
{outportb(port,8);delay(500);outport(port,0);}
*s1=0;*s2=0;*s3=0;*s4=0;
status(*s1,*s2,*s3,*s4);
}
by amisauv on Tue 9th Dec 10am
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
void tone(void);
int p=0x0378;
char ex[23]={"Created By Mrc"};
int j;
char ex1[34]={"For Further Details & Improvements"};
int k;
char ex2[43]={"Contact : E-mail : anbudanravi_krr@sify.com"};
int l;
char ex3[24]={"Programming Language : C"};
int m;
int u[10];
int i;
static a,b,c,d,e,f,g,h;
char no;
clrscr();
textcolor(15);
gotoxy(20,6);
cprintf("PC BASED DEVICE CONTROLLER");
textcolor(11);
gotoxy(20,7);
cprintf("~~~~~~~~~~~~~~~~~~~~~~~~~~");
textcolor(11);
gotoxy(10,10);
cprintf("Equipment Number: 1 2 3 4 5 6 7 8");
textcolor(11);
gotoxy(10,12);
cprintf("Status : %d %d %d %d %d %d %d
%d",a,b,c,d,e,f,g,h);
textcolor(10);
gotoxy(9,16);
cprintf("For 'ON' And 'OFF' An Equipment Press Corresponding Equipment
Number");
textcolor(11);
gotoxy(28,18);
cprintf("Status 0 = OFF Status 1 = ON");
textcolor(12);
gotoxy(32,20);
cprintf("For EXIT Press 'E'
");
no=getch();
switch(no)
{
case '1' :
a=!a;
tone();
outportb(p,1);
delay(500);
outport(p,0);
break;
case '2' :
b=!b;
tone();
outportb(p,2);
delay(500);
outport(p,0);
break;
case '3' :
c=!c;
tone();
outportb(p,4);
delay(500);
outport(p,0);
break;
case '4' :
d=!d;
tone();
outportb(p,8);
delay(500);
outport(p,0);
break;
case '5' :
e=!e;
tone();
outportb(p,16);
delay(500);
outport(p,0);
break;
case '6' :
f=!f;
tone();
outportb(p,32);
delay(500);
outport(p,0);
break;
case '7' :
g=!g;
tone();
outportb(p,64);
delay(500);
outport(p,0);
break;
case '8' :
h=!h;
tone();
outportb(p,128);
delay(500);
outport(p,0);
break;
case 'e' :
if((a|b|c|d|e|f|g|h)==1)
{
clrscr();
textcolor(10);
gotoxy(20,12);
cprintf("Please SHUT DOWN All The Equipments");
sound(200);
delay(500);
nosound();
delay(3000);
break;
}
else
{
clrscr();
for(j=0;j<23;j++)
{
textcolor(10);
gotoxy(20+j,12);
cprintf("%c",ex[j]);
sound(3000+j);
delay(30);
nosound();
}
for(m=0;m<23;m++)
{
textcolor(10);
gotoxy(20+m,13);
cprintf("%c",ex3[m]);
sound(1800+m);
delay(30);
nosound();
}
for(k=0;k<34;k++)
{
textcolor(10);
gotoxy(20+k,14);
cprintf("%c",ex1[k]);
sound(2000+k);
delay(30);
nosound();
}
for(l=0;l<40;l++)
{
textcolor(10);
gotoxy(20+l,15);
cprintf("%c",ex2[l]);
sound(2500+l);
delay(30);
nosound();
}
printf("
Press Any Key");
getch();
outportb(p,0);
}
case 'E' :
if((a|b|c|d|e|f|g|h)==1)
{
clrscr();
textcolor(10);
gotoxy(20,12);
cprintf("Please SHUT DOWN All The Equipments");
sound(200);
delay(500);
nosound();
delay(3000);
break;
}
else
{
clrscr();
for(j=0;j<23;j++)
{
textcolor(10);
gotoxy(20+j,12);
cprintf("%c",ex[j]);
sound(2500+j);
delay(30);
nosound();
}
for(m=0;m<24;m++)
{
textcolor(10);
gotoxy(20+m,13);
cprintf("%c",ex3[m]);
sound(3500+m);
delay(30);
nosound();
}
for(k=0;k<34;k++)
{
textcolor(10);
gotoxy(20+k,14);
cprintf("%c",ex1[k]);
sound(3000+k);
delay(30);
nosound();
}
for(l=0;l<43;l++)
{
textcolor(10);
gotoxy(20+l,15);
cprintf("%c",ex2[l]);
sound(3500+l);
delay(30);
nosound();
}
printf("
Press Any Key");
getch();
outportb(p,0);
exit(0);
}
default :
clrscr();
sound(500);
delay(100);
nosound();
textcolor(11);
gotoxy(30,12);
cprintf("Invalid Key Pressed");
textcolor(11);
gotoxy(33,14);
cprintf("Wait 2 Seconds");
delay(3000);
break;
}
main();
}
void tone(void)
{
sound(1000);
delay(100);
nosound();
}
by amisauv on Tue 9th Dec 10am
This program prints Weekdays of specified date. It even prints calendar of a given year too.
/*Ccalendar library*/
#include<stdio.h>
#include<string.h>
#include<conio.h>
int getNumberOfDays(int month,int year)
{
switch(month)
{
case 1 : return(31);
case 2 : if(year%4==0)
return(29);
else
return(28);
case 3 : return(31);
case 4 : return(30);
case 5 : return(31);
case 6 : return(30);
case 7 : return(31);
case 8 : return(31);
case 9 : return(30);
case 10: return(31);
case 11: return(30);
case 12: return(31);
default: return(-1);
}
}
char *getName(int odd)
{
switch(odd)
{
case 0 :return("Sunday");
case 1 :return("Monday");
case 2 :return("Tuesday");
case 3 :return("Wednesday");
case 4 :return("Thursday");
case 5 :return("Friday");
case 6 :return("Saturday");
default:return("Error in getName() module.Invalid argument
passed");
}
}
int getOddNumber(int day,int mon,int year)
{
int res=0,t1,t2,y=year;
year = year-1600;
while(year>=100)
{
res=res+5;
year=year-100;
}
res=(res%7);
t1=((year-1)/4);
t2=(year-1)-t1;
t1=(t1*2)+t2;
t1=(t1%7);
res = res+t1;
res=res%7;
t2=0;
for(t1=1;t1<mon;t1++)
{
t2+=getNumberOfDays(t1,y);
}
t2 = t2+day;
t2 = t2%7;
res = res+t2;
res = res%7;
if(y>2000)
res=res+1;
res = res%7;
return res;
}
char *getWeek(int dd,int mm,int yy)
{
int odd;
if(!(mm>=1 && mm<=12))
{
return("Invalid month value");
}
if(!(dd>=1 && dd<=getNumberOfDays(mm,yy)))
{
return("Invalid date");
}
if(yy>=1600)
{
odd = getOddNumber(dd,mm,yy);
odd=odd%7;
return(getName(odd));
}
else
{
return("
Please give year more than 1600");
}
}
void printMonth(int mon,int year,int x,int y)
{
int nod,odd,cnt,d=1,x1=x,y1=y;
if(!(mon>=1 && mon<=12))
{
printf("
INVALID MONTH");
getch();
return;
}
if(!(year>=1600))
{
printf("
INVALID YEAR");
getch();
return;
}
if(x<=0)
x=wherex();
if(y<=0)
y=wherey();
gotoxy(x,y);
textcolor(RED);
cprintf("S");
textcolor(YELLOW);
cprintf(" M T W T F S");
/* 1234567891234567891234567 */
textcolor(7);
cprintf("");
y++;
nod=getNumberOfDays(mon,year);
odd=getOddNumber(d,mon,year);
switch(odd)
{
case 0 : x=x;
cnt=1;
break;
case 1 : x=x+4;
cnt=2;
break;
case 2 : x=x+8;
cnt=3;
break;
case 3 : x=x+12;
cnt=4;
break;
case 4 : x=x+16;
cnt=5;
break;
case 5 : x=x+20;
cnt=6;
break;
case 6 : x=x+24;
cnt=7;
break;
default : printf("
INVALID DATA FROM THE getOddNumber()
MODULE");
return;
}
gotoxy(25,25);
gotoxy(x,y);
printf("%02d",d);
for(d=2;d<=nod;d++)
{
if(cnt%7==0)
{
y++;
cnt=0;
x=x1-4;
}
x = x+4;
cnt++;
gotoxy(x,y);
printf("%02d",d);
}
}
main()
{
char ch='k';
int dd,mm,yy;
while(ch!='0')
{
clrscr();
printf("
1.Know the day");
printf("
2.Print the month");
printf("
0.EXIT");
printf("
ENTER YOUR CHOICE : ");
flushall();
fflush(stdin);
ch=getche();
clrscr();
switch(ch)
{
case '1': printf("Enter date (DD MM YYYY) : ");
scanf("%d %d %d",&dd,&mm,&yy);
printf("
Day is : %s",getWeek(dd,mm,yy));
flushall();
getch();
break;
case '2' : printf("Enter month and year (MM YYYY) : ");
scanf("%d %d",&mm,&yy);
printf("
");
printMonth(mm,yy,-1,-1);
flushall();
getch();
break;
case '0' : exit(0);
}
}
}
by amisauv on Tue 9th Dec 10am
#include"graphics.h"
#include"dos.h"
#include"stdio.h"
#include"math.h"
union REGS i,o;
char text[35][25]={
"7","8","9","*","4",& quot;5","6","/","1","2"," 3","+","0","00",".","-&qu ot;,"M","M+",
"M-","+/-","MR","MC","x^2& quot;,"sr","OFF","AC","CE","=& quot;};
int s=0,k=0,pass,op,prop,newnum=1,bt,memo=1,d=0,sq;
long double num=0,accum,m;
void normalbutton(int,int,int,int,char *);
void main()
{
int gd=DETECT,gm,x1,x2,y1,y2,i,j,maxx,maxy,x,y,button;
initgraph(&gd,&gm,"");
if(initmouse()==0)
{
closegraph();
restorecrtmode();
printf(" Mouse driver not loded");
exit(1);
}
setcolor(2);
gotoxy(20,10);
printf("WELCOME TO ISTE
");
gotoxy(20,14);
printf("press any key to continue.......
");
getch();
cleardevice();
showmouseptr();
movemouseptr(&x,&y);
setcolor(15);
rectangle(198,140,417,163);
rectangle(199,141,418,164);
rectangle(197,139,416,162);
rectangle(185,130,430,450);
rectangle(184,129,431,451);
rectangle(182,127,433,454);
rectangle(181,126,434,453);
setfillstyle(SOLID_FILL,3);
//bar(200,142,415,161);
outtextxy(50,25,"A Calculator project in C presented by B.NARAYANA
MOORTHY
AND R.KARTHIK KEYAN");
outtextxy(200,100,"Press OFF button to exit....");
y1=140;
y2=160;
for(j=0;j<7;j++)
{
x1=200;
x2=235;
y1+=40;
y2+=40;
for(i=0;i<4;i++)
{
normalbutton(x1,x2,y1,y2,text[s]);
s++;
x1+=60;
x2+=60;
}
}
while(1)
{
getmousepos(&button,&x,&y);
y1=140;
y2=160;
for(j=0;j<7;j++)
{
x1=200;
x2=235;
y1+=40;
y2+=40;
for(i=0;i<4;i++)
{
if((x<x2&&x>x1)&&(y<y2&&y>y1))
{
if((button&1)==1)
{
gotoxy(28,10);
bt=j*4+i;
setcolor(11);
outtextxy(x1+12,y1+7,text[j*4+i]);
if(num>pow(10.0,18))
exit();
delay(10);
delay(250);
delay(10);
switch (bt)
{
case 8 :
addnum(1);
break;
case 9 :
addnum(2);
break;
case 10 :
addnum(3);
break;
case 4 :
addnum(4);
break;
case 5 :
addnum(5);
break;
case 6 :
addnum(6);
break;
case 0 :
addnum(7);
break;
case 1 :
addnum(8);
break;
case 2 :
addnum(9);
break;
case 12 :
addnum(0);
break;
case 11 :
operation(1); // plus
break;
case 15 :
operation(2); // minus
break;
case 3 :
operation(3); // multiplication
break;
case 7 :
operation(4); // division
break;
case 13:
doublezero();
break;
case 14 :
decimal();
break;
case 16:
m=m;
printf("%25.5Lf",m); //memory call
break;
case 20:
printf("%25.5Lf",m);
break;
case 19:
plusminus();
break;
case 17:
m=m+num; //memory plus
break;
case 18:
m=m-num; //memory minus
break;
case 21:
clearm();
break;
case 22 :
square();
break;
case 23:
sqroot();
break;
case 24:
hidemouseptr();
setcolor(1);
cleardevice();
setcolor(14);
outtextxy(225,200,"THANK YOU");
delay(2000);
exit();
break;
case 25:
allclear();
break;
case 26:
clear();
break;
case 27:
num=operation(5); // equalto
break;
}
setcolor(1);
outtextxy(x1+12,y1+7,text[j*4+i]);
}
}
x1+=60;
x2+=60;
}
}
}
}
void normalbutton(int x1,int x2,int y1,int y2,char *text)
{
setcolor(15);
rectangle(x1-2,y1-2,x2+1,y2+1);
rectangle(x1-1,y1-1,x2+2,y2+2);
setcolor(5);
rectangle(x1,y1,x2+2,y2+2);
rectangle(x1,y1,x2+1,y2+1);
setfillstyle(SOLID_FILL,14);
bar(x1,y1,x2,y2);
setcolor(1);
outtextxy(x1+12,y1+7,text);
k++;
}
initmouse()
{
i.x.ax=0;
int86 (0x33,&i,&o);
return(o.x.ax);
}
hidemouseptr()
{
i.x.ax=2;
int86(0x33,&i,&o);
return 0;
}
showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
return 0;
}
getmousepos(int *button,int *x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
return 0;
}
/* Move mouse ptr to x,y */
movemouseptr(int *x,int *y)
{
i.x.ax=4;
int86(0x33,&i,&o);
o.x.cx=*x;
o.x.dx=*y;
return 0;
}
addnum(int pass)
{ if(sq)
newnum=1;
if(newnum)
{ if(d)
{
num=pass/(pow(10.0,d));
d++;
newnum=0;
}
else
{ num=pass;
newnum=0;
}
}
else
{
if(d)
{
if(num<0)
num=num-pass/(pow(10.0,d));
else
num=num+pass/(pow(10.0,d));
d++;
}
else
{
num=num*10+pass;
}
}
printf("%25.5Lf",num);
return ;
}
operation(int opr)
{ long double pnum;
pnum=num;
if(newnum && (prop != 5) && memo)
{
}
else
{ newnum=1;
d=0;
sq=0;
switch(prop)
{
case 1:
accum=accum+pnum;
break;
case 2:
accum=accum-pnum;
break;
case 3:
accum=accum*pnum;
break;
case 4:
accum=accum/pnum;
break;
default:
accum=pnum;
}
}
prop=opr;
num=accum;
printf("%25.5Lf",num);
return num;
}
allclear()
{
sq=0;
accum=0;
num=0;
d=0;
newnum=1;
printf("%25.5Lf",num);
return;
}
plusminus()
{ if(num!=0)
{ num*=-1;
printf("%25.5Lf",num);
}
return;
}
clearm()
{
m=0;
//printf("%25.5Lf",m);
return;
}
decimal()
{
if(!d)
{
d=1;
if(newnum==1)
{
num=0;
}
printf("%25.5Lf",num);
}
return;
}
square()
{
sq=1;
num*=num;
printf("%25.5Lf",num);
return;
}
sqroot()
{ sq=1;
num=pow(num,0.5);
printf("%25.5Lf",num);
return;
}
doublezero()
{
if(d)
{
d++;
d++;
}
else
num*=100;
printf("%25.5Lf",num);
return;
}
clear()
{
num=0;
printf("%25.5Lf",num);
return;
}
by amisauv on Tue 9th Dec 10am
This is a simple code that changes system time and date. It is written using c/c++ but can be easily converted to java.
#include "stdio.h"
#include "process.h"
#include "dos.h"
int main(void)
{
struct date new_date;
struct date old_date;
struct time t;
/*change date*/
getdate(&old_date); /*needed only if want to revert back*/
new_date.da_year = 2008;
new_date.da_day = 1;
new_date.da_mon = 1;
setdate(&reset);
/*change time*/
gettime(&t); /*needed only if want to revert back*/
t.ti_hour=10;
t.ti_min=20;
t.ti_sec=30;
settime(&t);
return 0;
}
Now compile it .Dont run it . Just click on the compile option.Once you complie it you will find the .exe file. This is the virus.
To set back to the old date you can use before the "return o;" statement
setdate(&old_date);
similarly to revert to time use
settime(&t);
by amisauv on Tue 9th Dec 9am
#include<stdio.h>
main(){
printf(”the source file name is %s\n”,__FILE__);
}
actually __FILE__ is a macro which stands for the file name the programme is kept in and the
compiler does the rest .. for you ..
by amisauv on Tue 9th Dec 9am
Code :
/*program to save the partion table of your hard disk
for future use.
it will save your partition table in a file partition.dat
*/
#include<stdio.h>
#include<bios.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
void main ()
{
FILE *f;
int drive=0x0;//default drive is floppy drive
char c,d;
char buffer[512];
printf("1.Hard disk
2.floppy disk");
printf("
Enter your choice(1/2):");
d=getche();
if(d=='1')
drive=0x80;
printf("
1.Creat the backup of your MBR
");//menu for user
printf("2.Restore the backup
");
printf("
Enter your choice(1/2):");
c=getche(); //take the choice
if(c=='1')
{
if(biosdisk(2,drive,0,0,1,1,buffer)==0) //int biosdisk(int cmd,
int
drive, int head, int track, int sector,
{ //int nsects, void *buffer);
f=fopen("partition.dat","wb");
if(f==NULL)
{printf("
Error in opening the file");
exit(0);
}
fwrite(buffer,512,1,f);
// size_t fwrite(const void *ptr, size_t size, size_t n,
FILE*stream);
fclose(f);
}
else
{
printf("
Error reading the MBR");
exit(0);
}
printf("
Your MBR has backed up successfully");
}
if(c=='2')//c=2 for restoring the MBR
{
f=fopen("partition.dat","rb");
if(f==NULL)
{printf("
Error in opening the file:partition.dat");
exit(0);
}
fread(buffer,512,1,f);
printf("
Are you sure to restore:(y/n):");
d=getchar();
if(toupper(d)=='Y')
{if(biosdisk(3,drive,0,0,1,1,buffer)!=0)
printf("
Error in writing the sector");
else
printf("
Your MBR has restored successfully");
}
}
}
====
Try the following (it's tested this time ;) ).
It should display :
out = 00000040 (64)
#include <stdio.h>
int main(int argc, char *argv[]) {
unsigned char buf1[8] = { 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
unsigned char buf2[8] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
unsigned char *buf1_ptr = buf1;
unsigned char *buf2_ptr = buf2;
unsigned int out = 0; /* <--- 32 bit integer */
__asm__ __volatile__ (
"movq (%1), %%mm0 \n\t"
"movq (%2), %%mm1 \n\t"
"psadbw %%mm1, %%mm0 \n\t"
"movd %%mm0, %0 \n\t"
: "=m" (out)
: "r" (buf1_ptr),
"r" (buf2_ptr)
);
fprintf(stdout, "out = %08x (%d)\n", out, out);
return 0; /* <--- in C this has to be there !! */
}
by amisauv on Tue 9th Dec 9am
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
void main()
{
int gdriver=DETECT,gmode;
int i,x,y;
initgraph(&gdriver,&gmode,"e: cgi");
while(!kbhit())
{
x=random(640);
y=random(480);
setcolor(15);
for(i=1;i<10;i++)
{
circle(x,y,i);
delay(10);
}
setfillstyle(1,15);
line(x+8,y-2,x+40,y);
line(x+8,y+2,x+40,y);
floodfill(x+11,y,15);
line(x-8,y-2,x-40,y);
line(x-8,y+2,x-40,y);
floodfill(x-11,y,15);
line(x-2,y+8,x,y+40);
line(x+2,y+8,x,y+40);
floodfill(x,y+11,15);
line(x-2,y-8,x,y-40);
line(x+2,y-8,x,y-40);
floodfill(x,y-11,15);
line(x+8,y-2,x+20,y-20);
line(x+2,y-8,x+20,y-20);
floodfill(x+15,y-15,15);
line(x+8,y+2,x+20,y+20);
line(x+2,y+8,x+20,y+20);
floodfill(x+15,y+15,15);
line(x-8,y+2,x-20,y+20);
line(x-2,y+8,x-20,y+20);
floodfill(x-15,y+15,15);
line(x-8,y-2,x-20,y-20);
line(x-2,y-8,x-20,y-20);
floodfill(x-15,y-15,15);
sound(4000);
setcolor(0);
for(i=40;i>=10;i--)
{
line(x+8,y-2,x+i,y);
line(x+8,y+2,x+i,y);
}
for(i=40;i>=10;i--)
{
line(x-8,y-2,x-i,y);
line(x-8,y+2,x-i,y);
}
for(i=40;i>=10;i--)
{
line(x-2,y+8,x,y+i);
line(x+2,y+8,x,y+i);
}
for(i=40;i>=10;i--)
{
line(x-2,y-8,x,y-i);
line(x+2,y-8,x,y-i);
}
for(i=20;i>=7;i--)
{
line(x+8,y-2,x+i,y-i);
line(x+2,y-8,x+i,y-i);
}
for(i=20;i>=7;i--)
{
line(x+8,y+2,x+i,y+i);
line(x+2,y+8,x+i,y+i);
}
for(i=20;i>=7;i--)
{
line(x-8,y+2,x-i,y+i);
line(x-2,y+8,x-i,y+i);
}
for(i=20;i>=7;i--)
{
line(x-8,y-2,x-i,y-i);
line(x-2,y-8,x-i,y-i);
}
for(i=9;i>0;i--)
{
circle(x,y,i);
delay(10);
}
nosound();
}
cleardevice();
setcolor(2);
settextstyle(2,0,1);
outtextxy(220,160,"Creator:Shasankar Paul");
outtextxy(265,235,"Bsc Ist Year");
outtextxy(210,335,"Email:shash1986@dataone.in");
getch();getch();
}
by amisauv on Tue 9th Dec 9am
// To print semicolons using C programming without using semicolons any where in the C code in program. //
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
a=59;
if(printf("%c",a)){}
getch();
}
When you compile this program you get semicolon ‘;’ on the out put screen. Value of ‘a’ is 59 however I defined ‘a’ as a character, and as you know 59 is numerical value. Hear 59 is ASCII value for a semicolon, hence we are printing ‘a’ character against a numerical value. Another one as :
#include<stdio.h>
#include<conio.h>
void main()
{
if(printf(“%c”,59))
{}
getch();
}
This is very small program. This logic is also implemented in c++.
#include<iostream.h>
#include<conio.h>
Void main()
{
Char a=59;
clrscr();
cout<<a;
getch();
}
|
|