Source Code
Source Code
Source Code
h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<windows.h>
#include<time.h>
#define ENTER 13
#define BKSP 8
#define SPACE 32
#define TAB 9
{ WORD wColor;
HANDLE hStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
if(GetConsoleScreenBufferInfo(hStdOut,&csbi))
// SetConsoleTextAttributes(hStdOut,wColor);
SetConsoleTextAttribute(hStdOut,wColor);
struct item
char productname[40],productcomp[40],c;
int productid;
int price;
int Qnt;
}st;
void wel_come(void);
void title(void);
void login();
void menu(void);
void title(void);
void deleteproduct(void);
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
void add_item();
void read_item();
void search_item();
void edit_item();
void main(void)
void wel_come(void)
{
time_t t;
time(&t);
printf(" \n");
printf("---------------------------------------------------------------------------------------------------------\n");
printf("\t\t\t\t\t%s",ctime(&t));
printf("---------------------------------------------------------------------------------------------------------\n");
printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");
printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");
printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");
printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");
printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");
printf("|\t\t\t\t==================================\t\t\t\t\t\t|\n");
printf("|\t\t\t\t==================================\t\t\t\t\t\t|\n");
printf("|\t\t\t\t\t Number\t\t\t\t\t\t\t\t|\n");
printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");
printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");
printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");
printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");
printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");
printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");
printf("|\t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n");
printf("---------------------------------------------------------------------------------------------------------\n");
getch();
system("cls");
void login()
int a=0,i=0;
char pword[10],code[10];
char user[10]="user";
char pass[10]="pass";
do
printf(" \n USERNAME:-");
scanf("%s", &uname);
printf(" \n PASSWORD:-");
while(i<10)
pword[i]=getch();
c=pword[i];
if(c==13) break;
else printf("*");
i++;
pword[i]='\0';
//char code=pword;
i=0;
//scanf("%s",&pword);
if(strcmp(uname,"user")==0 && strcmp(pword,"pass")==0)
break;
else
a++;
while(a<=2);
if (a>2)
printf("\nSorry you have entered the wrong username and password for four
times!!!");
getch();
system("cls");
menu();
}
void menu(void)
int choice;
system("cls");
main:
printf(" ");
printf(" ");
scanf("%i", &choice);
system("cls");
switch(choice)
case 1:
add_item();
break;
case 2:
deleteproduct();
break;
case 3:
search_item();
break;
case 4:
read_item();
break;
case 5:
edit_item();
break;
case 6:
printf("System Exit");
exit(0);
break;
default:
getch();
void add_item()
char c;
int a=0;
FILE *fp;
do
{
system("cls");
I:
scanf("%i",&ID);
/*
*/
if(ID == st.productid)
goto I;
st.productid = ID;
scanf("%i",&st.productid);
}
do
fflush(stdin);
st.productname[0]=toupper(st.productname[0]);
if(isalpha(st.productname[index]))
valid = 1;
else
valid = 0;
break;
if (!valid)
getch();
do
char productcomp[40];
fflush(stdin);
st.productcomp[0]=toupper(st.productcomp[0]);
if(isalpha(st.productcomp[index]))
valid = 1;
else
valid = 0;
break;
if (!valid)
getch();
}while(!valid);
//productid
do
{
printf("\nPrice [10-5000]Rupees:");
scanf("%i",&st.price);
if(st.price<10 || st.price>5000)
}while(st.price<10 || st.price>5000);
do
printf("\nQuantity [1-500]\t:");
scanf("%i",&st.Qnt);
if(st.Qnt<1 || st.Qnt>500)
}while(st.Qnt<1 || st.Qnt>500);
// scanf("%i", &st.price);
//scanf("%i", &st.productid);
// scanf("%i",&st.Qnt);
fp=fopen("NextFile.dat","a");
fclose(fp);
printf("\nPress 'Enter' to add more item and any other key to go to main menu");
}
menu();
void search_item()
char target[40];
int found=0;
FILE *sfile;
sfile=fopen("NextFile.dat","r");
fflush(stdin);
gets(target);
target[0]=toupper(target[0]);
if(strcmp(target, st.productname)==0)
found=1;
if(found)
else
fclose(sfile);
menu();
void deleteproduct(void)
char target[40];
int found=0;
sfile=fopen("NextFile.dat","r");
tfile=fopen("TempFile.dat","w+");
fflush(stdin);
scanf("%s",target);
target[0]=toupper(target[0]);
if(strcmp(target,st.productname)==0)
found=1;
}
else
if(!found)
getch();
menu();
else
fclose(sfile);
fclose(tfile);
remove("NextFile.dat");
rename("TempFile.dat","NextFile.dat");
menu();
void read_item()
FILE *f;
int i, q;
if((f=fopen("NextFile.dat","r"))==NULL)
{
gotoxy(10,3);
printf("NO RECORDS");
getch();
menu();
else
gotoxy(0,5);
for(i=0;i<100;i++)
printf("-");
gotoxy(5,6);
printf("Product Name");
gotoxy(25,6);
printf("Product Price");
gotoxy(40,6);
printf("Product Company");
gotoxy(60,6);
printf("Product CODE");
gotoxy(80,6);
printf("Product Quantity\n");
for(i=0;i<100;i++)
{
printf("-");
q=8;
gotoxy(5,q);
printf("%s",st.productname);
gotoxy(25,q);
printf("%i",st.price);
gotoxy(40,q);
printf("%s",st.productcomp);
gotoxy(60,q);
printf("%i",st.productid);
gotoxy(80,q);
printf("%i",st.Qnt);
q++;
printf("\n");
for(i=0;i<100;i++)
printf("-");
fclose(f);
getch();
menu();
}
void edit_item()
char target[40];
int a=0;
int id;
char edit;
if((fp=fopen("NextFile.dat","r+"))==NULL)
menu();
else
rp = fopen("TempFile.dat","a");
system("cls");
scanf("%i",&id);
fflush(stdin);
if(id==st.productid)
a=1;
printf("\nProduct Quantity\t:%i",st.Qnt);
do
fflush(stdin);
st.productname[0]=toupper(st.productname[0]);
if(isalpha(st.productname[index]))
valid = 1;
else
valid = 0;
break;
if (!valid)
getch();
}
}while(!valid); //while end here
//Product Company
do
char productcomp[40];
fflush(stdin);
st.productcomp[0]=toupper(st.productcomp[0]);
if(isalpha(st.productcomp[index]))
valid = 1;
else
valid = 0;
break;
if (!valid)
getch();
}while(!valid);
do
scanf("%i",&st.price);
if(st.price<10 || st.price>5000)
}while(st.price<10 || st.price>5000);
scanf("%i",&st.productid);
do
scanf("%i",&st.Qnt);
if(st.Qnt<1 || st.Qnt>500)
}while(st.Qnt<1 || st.Qnt>500);
edit=getche();
if(edit=='y' || edit=='Y')
else
fflush(stdin);
if(!a)
fclose(rp);
fclose(fp);
remove("NextFile.dat");
rename("TempFile.dat","NextFile.dat");
getch();
menu();
Output: