Thursday, February 4, 2010

A C Program for Shops

//Visit http://sanjayrnath.blogspot.com
#include
#include
#include
#include
void insert(void);
void shop(void);
int check(void);
int pcheck(void);
void dandt(void);
void main()
{
int driver=DETECT,mode,s1;
int exit;
FILE *fp;
clrscr();
printf(" Loading Powerful 512MB accelerated graphics from\nSANJAY incorporate company ltd.\n\a");
sleep(1);
clrscr();
//initgraph(&driver,&mode,"L:\\turbocpp\\cga.bgi");
//setbkcolor(9);
//closegraph();
do
{
printf("\nWhat do You Want to do? insert(1) or shop(2)");
scanf("%d",&s1);
switch(s1)
{
case 1:
insert();
break;
case 2:
shop();
break;
default:
printf("Wrong choice");
}
printf("\n\n\nPress 1 to exit or 2 to goto menu");
scanf("%d",exit);
}
while(exit==2);
printf("\n\nBye");
getch();
}
void insert(void)
{

int pass,quantity,exit1,driver1=DETECT,mode1;
float price;
char item[40],code[10];
FILE *fp1,*ck;
//initgraph(&driver1,&mode1,"L:\\turbocpp\\cga.bgi");
//setbkcolor(6);
do
{
printf("\nType Item code: ");
scanf("%s",&code);
ck=fopen(code,"r");
if(ck!=NULL)
{
printf("\n\nCode already exists\n\n");
fclose(ck);
insert();
}
else
{
fclose(ck);
fp1=fopen(code,"w");
printf("\n\nType Item Name: ");
scanf("%s",&item);
printf("\n\nType Item price: ");
scanf("%f",&price);
printf("\n\nType Current Quantity: ");
scanf("%d",&quantity);
fprintf(fp1," %s\t%s\t%d\t%f",code,item,quantity,price);
printf("\n\n\n\nSuccessfully Written To File Name: %d",code);
fclose(fp1);
clrscr();
printf("\n\nDo You Want To add again(1) or not(2)");
scanf("%d",&exit1);
}
}
while(exit1==1);
}
int pcheck(void)
{
int password=123,passc,count=1;
do
{
printf("Type Password:");
scanf("%d",&passc);
if(passc!=password)
{
count++;
printf("\n\nWrong Password\n\n");
}
else
return(1);
}
while(count!=3);
}
void shop(void)
{
int driver2=DETECT,mode2,pass,bord,wer=0,count2=0,squantity;
char scode[10],v;
FILE *sp,*ck1;
clrscr();
initgraph(&driver2,&mode2,"L:\\turbocpp\\cga.bgi");
setbkcolor(6);
pass=pcheck();
if(pass!=1)
printf("\n\nBYE");
else
{
do
{
for(bord=0;bord<79;bord++)
printf("=");
//dandt();
printf("\n\nType Item Code: ");
scanf("%s",scode);
ck1=fopen(scode,"r");
if(ck1==NULL)
{
printf("\n\nItem Does not exists exists\n\n");
fclose(ck1);
wer=1;
count2++;
if(count2==3)
wer=0;
}
}
while(wer==1);
else
{
sp=fopen(scode,"r");
printf("\n\nProduct Information\n\n");
while((v=getc(sp))!=EOF)
printf("%c",v);
write2screen
getconfiguration();

A C Program for playing SARIGAMA

#include
#include
#include
#include
void main()
{
int i,j=0;
clrscr();
printf("Sanjay R Nath");
printf("\n\nSARIGAMA");
for(i=500;i<4000;i=i)
{
if(j!=0)
printf("\n\nSARIGAMA");
sound(i);
printf("\n\nPress a Key For Next tone\n");
getch();
clrscr();
nosound();
i=i+500;
j++;
}
sound(10000);
printf("\n\nHope You Have enjoyed\n\nMy new version 1.0 will be launching shorty\n");
getch();
nosound();
}

A simple C program to add two numbers

//program using functions
#include
#include
get(int,int);
void main()
{
int a,b,sum;
clrscr();
printf("Type two numbers");
scanf("%d",&a);
scanf("%d",&b);
sum=get(a,b);
printf("Sum=%d",sum);
getch();
}
get(a,b)
{
int sum;
sum=a+b;
return(sum);
}

Mind Reader This is VERY Interesting! Try it.

//Visit http://sanjayrnath.blogspot.com
//The Mind Reader
//Version 1.0
#include
#include
#include
#include

void fun(int x,int y,int n,int a)
{
textcolor(13);
gotoxy(x,y);
cprintf("%d->%c",n,a);
}
void box(int c,int r,int s,int y)
{
int i ;
textcolor(3);
gotoxy(s,y);
cprintf("%c",218);



for(i=s+1;i {
gotoxy(i,y);
cprintf("%c",196);
}
for(i=s+1;i {
gotoxy(i,r);
cprintf("%c",196);
}

gotoxy(c,y);
cprintf("%c",191);

for(i=y+1;i{
gotoxy(s,i);
cprintf("%c",179);

}

for(i=y+1;i{
gotoxy(c,i);
cprintf("%c",179);
}
gotoxy(s,i);
cprintf("%c",192);
gotoxy(c,i);
cprintf("%c",217);


}

void help()
{
box(78,24,2,1);
box(70,9,52,5);
box(77,23,30,15);

gotoxy(50,15);
printf("Play Like This");
gotoxy(31,16);
printf("1.Choose a two digit number and add the digits");
gotoxy(31,17);
printf("2.Subtract the sum from original number");
gotoxy(31,18);
printf("3.See the symbol opposit to the number you got");
gotoxy(31,19);
printf("4.Press any key The MIND READER will ");
gotoxy(31,20);
printf(" display the symbol you got");
gotoxy(31,21);
printf("5.For Best Results Please don't Turn your ");
gotoxy(31,22);
printf(" Eyes from the screen");

}
void ran()
{
time_t t;
int r,i;
int a[]={1,2,3,4,5,6,14,15,16,17,18,19,20,21,22,23,24,25,27,29,
30,33,34,35,36,37,38,40,41,42,43,60,62,61,63,64,123,124,
125,126,127,128,154,155,156,171,172,174,175,229,234,235,
236,237,238,239, 240,242,243,244,245,246,247,251,254};

srand((unsigned) time(&t));
r=rand() % 65;
help();
textcolor(10);
gotoxy(48,2);
delay(2000);
cprintf("M");
delay(200);
cprintf("I");
delay(200);
cprintf("N");
delay(200);
cprintf("D");
delay(200);
cprintf(" R");
delay(200);
cprintf("E");
delay(200);
cprintf("A");
delay(200);
cprintf("D");
delay(200);
cprintf("E");
delay(200);
cprintf("R");
delay(200);
cprintf(" F");
delay(200);
cprintf("R");
delay(200);
cprintf("O");
delay(200);
cprintf("M");
delay(200);
cprintf(" S");
delay(200);
cprintf("A");
delay(200);
cprintf("N");
delay(200);
cprintf("J");
delay(200);
cprintf("A");
delay(200);
cprintf("Y");
delay(200);
cprintf(" R");
delay(200);
cprintf(" N");
delay(200);
cprintf("A");
delay(200);
cprintf("T");
delay(200);
cprintf("H");
delay(200);
gotoxy(26,45);
sleep(3);
cprintf("If U Can Break it Then Break It!");
gotoxy(30,48);
sleep(3);
cprintf("Its A Challenge from SRN");

for(i=1;i<23;i++)
{
textcolor(13);
gotoxy(3,i+1);
cprintf("%d->%c ",i,a[rand()%65]);
gotoxy(10,i+1);
cprintf("%d->%c ",i+22,a[rand()%65]);
gotoxy(17,i+1);
cprintf("%d->%c ",i+44,a[rand()%65]);
gotoxy(24,i+1);
cprintf("%d->%c ",i+66,a[rand()%65]);
}
fun(3,10,9,r);
fun(3,19,18,r);
fun(10,6,27,r);
fun(10,15,36,r);
fun(17,2,45,r);
fun(17,11,54,r);
fun(17,20,63,r);
fun(24,7,72,r);
fun(24,16,81,r);

for(i=1;i<12;i++)
{
gotoxy(31,i+1);
cprintf("%d->%c ",i+88,a[rand()%65]);
}
gotoxy(55,7);
textcolor(15+BLINK);
cprintf("Press Any Key");
getch();
gotoxy(55,7);
textcolor(BLACK);
cprintf("Press Any Key");
gotoxy(61,7);
textcolor(15+BLINK);
cprintf("%c",r);
}

void main()
{
int i;
clrscr();

ran();
getch();
}
//Later versions will be posting shortly

A C Program for Diary Purposes

//daily Graphics diary
//Version 1.0
#include
#include
#include
int newuser(void);
int current(int);
void view(void);
void add(void);
void pchanger(int);
struct diary
{
int time,date;
char content[200],name[20];
struct diary *p;
}dy;

void main()
{
FILE *fp,*fp1,*fp2;
int driver=DETECT,mode,j;
int i,c2,password=123,new1,current1,nch;
char c1,gra;
clrscr();
printf("Do You Like Graphics(y/n)\n");
clrscr();
initgraph(&driver,&mode,"L:\\turbocpp\\cga.bgi");
setbkcolor(9);
setcolor(6);
rectangle(350,270,80,230);
for(j=0;j<50;j++)
{
setcolor(j);
circle(550,120,j);
}
settextstyle(4,HORIZ_DIR, 10);
outtext("DIARY");
printf("\t\t\t\tDIARY\t2010\n");
printf("================================================================================");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\t\tAre You a new user(Y/N) or view file(v)\n\n");
scanf("%c",&c1);
switch(c1)
{
case 'y' :
new1=newuser();
printf("\n\nDo you want to view your diary(1) or add(2) or exit(3)");
scanf("%d",&nch);
if(nch==1)
view();
else if(nch==2)
add();
else
printf("\n\nThank You");
break;
case 'n' :
current1=current(password);
break;
case 'v':
view();
default:
printf("Wrong choice\n\n\n\n");
}
if(current1==1)
printf("Current User Status=Success\t\a\n");
else
printf("Current User Status=Failed\t\a\n");
if(new1==1)
printf("New User Status=Success\t\a\n");
else
printf("New User Status=Failed\t\a\n");
if(current1!=1&&new1!=1)
{
settextstyle(1,HORIZ_DIR, 7);
outtextxy(40,260,"PROGRAM FAILED");
}
else
{
printf("\n\n\n\n\n\n\n\n\a\t\t Program created by SANJAY\n\t\t ~~~~~~~ ~~~~~~~ ~~ ^^^^^^\n\n\n\t\t\t\t\t\t\t Copyright 2010\n\n\n\t\t\t\t\t\t\t All rights reserved");
printf("\n\n================================================================================");
}
getch();
}
int newuser(void)
{
int time,date,t=1;
char name[20],content[500];
FILE *fp;
clrscr();
printf("================================================================================");
printf("\t\t\tWelcome\n\n\nType your name(please type .txt after entering your name\n");
scanf("%s",&name);
printf("\n\nType today's Date\n");
scanf("%d",&date);
printf("\n\nType time(eg 1130)\n");
scanf("%d",&time);
printf("\n\nType content of what happened in ur dairy\n\n");
scanf("%s",&content);
fp=fopen(name,"a+");
fprintf(fp,"\n\n\n\t\t\t\t%s DIARY\n\n\n\nDate-%d\nTime:%d\n\nContent:%s",name,date,time,content);
printf("Successfully written to file");
printf("\n\n================================================================================");
fclose(fp);
return(t);
}
int current(int password)
{
FILE *fpp;
int mt,pchange,pass,i,j,name1[20],time1,date1,content1,t1=1,driver1=DETECT,mode1,auth=1;
clrscr();
initgraph(&driver1,&mode1,"L:\\turbocpp\\cga.bgi");
setbkcolor(14);
//printf("What You want to do? View password(1) or Continue(2)\n\n");
//scanf("%d",pchange);
//if(pchange==1)
//{
//pchanger(password);
//auth=8;
//}
//else
//{
//if(auth==1)
//{
printf("================================================================================");
printf("\nType password");
scanf("%d",&pass);
if(pass==password)
{
printf("\nPassword is correct\n\nType your name to continue.(Type .txt after typing your name)\n");
scanf("%s",&name1);
printf("\nCkecking Name\n\n\nPlease Wait\a\n\n");
fpp=fopen(name1,"a");
if(fpp==NULL)
printf("File cannot be opened");
else if(ferror(fpp)!=0)
printf("An error have occured\n\n");
else if(feof(fpp))
printf("Error\n\n");
else
{
do
{
printf("Do you want to add content(1) or view your diary(2)\n or exit(3)");
scanf("%d",&i);
switch(i)
{
case 1:
add();
break;
case 2:
view();
break;
case 3:
printf("\nbye\n");
break;
default:
{
printf("Wrong Choice");
j=1;
}
}
printf("\n\nPress 1 to exit or 2 to return to menu\n");
scanf("%d",&j);
}
while(j==2);
}
}
fclose(fpp);
printf("\n================================================================================");
return(t1);
return(6);
}
void add()
{
int time2,date2,driver2=DETECT,mode2;
char name2[20],content2[500];
FILE *ffp;
clrscr();
initgraph(&driver2,&mode2,"L:\\turbocpp\\cga.bgi");
setbkcolor(14);
printf("\n================================================================================");
printf("\t\t\t\nWelcome\n\n\nType ur name with .txt at end");
scanf("%s",name2);
printf("\n\nType today's Date");
scanf("%d",&date2);
printf("\n\nType time(eg 1130)");
scanf("%d",&time2);
printf("\n\nType content of what happened in ur dairy\n\n");
scanf("%s",&content2);
ffp=fopen(name2,"a+");
fprintf(ffp,"\n\n\n\t\t\t\t%s DIARY\n\n\nDate-%d\nTime:%d\n\nContent:%s",name2,date2,time2,content2);
printf("Successfully written to file");
fclose(ffp);
printf("\n\n================================================================================");
}
void view()
{
FILE *fg;
int passw=123,passw1,driver3=DETECT,mode3;
char nam[20],v,asd;
clrscr();
initgraph(&driver3,&mode3,"L:\\turbocpp\\cga.bgi");
setbkcolor(14);
printf("\n\n================================================================================");
printf("\n\nWith View Function You can view files\n\n");
printf("\n\nType Password");
scanf("%d",&passw1);
if(passw1!=passw)
printf("Password is incorrect");
else
{
do
{
printf("Type your name with .txt at end\n");
scanf("%s",&nam);
fg=fopen(nam,"r");
while((v=getc(fg))!=EOF)
printf("%c",v);
printf("\n\nDo you want to view again(1)or not(2)\n");
scanf("%d",&asd);
}
while(asd==1);
fclose(fg);
printf("\n\n\nYou have successfully read your diary\n\nBye\a");
printf("\n\n================================================================================");
}
}
void pchanger(int password)
{
FILE *pc;
int key,secret=111;
char pname[20];
clrscr();
printf("Prove That you are authorized by giving your secret ID Number\n\n");
scanf("%d",&key);
printf("\n\nEntering Network...\a...\n\nChecking Your ID..\a...");
if(key!=secret)
printf("You are un authorized\n\nGet Out Now or the Alarm will be switched ON");
else
{
printf("Enter name");
scanf("%s",&pname);
pc=fopen("passviewed.txt","a+");
fprintf(pc,"\t\t\t\tPassword Viewers\n\nName:- %s\t\tID:-%d\n\n",pname,key);
fclose(pc);
printf("\n\n\n%dPASSWORD = %d",password);
}
}
//latest versions will be posting shortly
//Further assistance contact srnassist@gmail.com