how do i put a password, change password on my code because everytime i put it in, my program don't shows it it just jumping to my selection menu, and how do i delete informations that ive put on my program? this is my code.
thank you in advance.
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <dos.h>
#include <stdlib.h>
#define p printf
#define s scanf
struct records
{
char name[20],address[50], contact[12];
int recno;
} rec;
void addemp();
void display();
FILE *emp;
void main()
{
char choice;
do
{
clrscr();
p("[A] - Add Record");
p("\n[D] - Display Record");
p("\n[X] - Exit");
p("\nEnter Choice: ");
choice=toupper(getch());
switch(choice)
{
case 'A':
addemp();
break;
case 'D':
display();
break;
case 'X':
exit(0);
break;
default:
p("Invalid Input");
}
}while(choice!='X');
}
void addemp()
{
if ((emp=fopen("d:\\emp.txt","a+"))==NULL)
{
p("Handled File");
delay(500);
}
else
{
while(!feof(emp))
{
fread(&rec.name,sizeof(char),20,emp);
fread(&rec.address,sizeof(char),20,emp);
fread(&rec.contact,sizeof(char),20,emp);
fread(&rec.recno,sizeof(int),20,emp);
}
clrscr();
rec.recno=rec.recno+1;
p("Record no.: %.4d\n",rec.recno);
p("Name: ");
gets(rec.name);fflush(stdin);
p("Address: ");
gets(rec.address);fflush(stdin);
p("Contact: ");
gets(rec.contact);fflush(stdin);
fwrite(&rec.name,sizeof(char),20,emp);
fwrite(&rec.address,sizeof(char),20,emp);
fwrite(&rec.contact,sizeof(char),20,emp);
fwrite(&rec.recno,sizeof(int),20,emp);
clrscr();
p("Record Saved");
delay(500);
}
fclose(emp);
main();
}
void display()
{
if ((emp=fopen("d:\\emp.txt","r"))==NULL)
{
p("Handled File");
delay(500);
}
else
{
while(!feof(emp))
{
clrscr();
fread(&rec.name,sizeof(char),20,emp);
fread(&rec.address,sizeof(char),20,emp);
fread(&rec.contact,sizeof(char),20,emp);
fread(&rec.recno,sizeof(int),20,emp);
p("Record no.: %.4d",rec.recno);
p("\nName: %s",rec.name);
p("\nAddress: %s",rec.address);
p("\nContact: %s",rec.contact);
getch();
}
}
fclose(emp);
main();
}