Sunteți pe pagina 1din 14

LINUX PROGRAMMING PROJECT

“PERSONAL DIARY MANAGEMENT SYSTEM”

K.VENKATSAI(16311A12L3)

K.SAGAR(16311A12L4)

K.SAIKUMAR(16311A12L5)

S.MONISHA(16311A12L6)
Mini project in C Personal Diary Management System is a console
application without graphics. In this project, user can keep their personal record
like they do in a diary. You can keep records of the important things you do in
your daily life, like meetings and various other tasks.

This mini project on Personal Diary Management in C is compiled in


Code::Blocks IDE using GCC compiler. It is complete and totally error-free.

About Personal Diary Management System:


In this console application, you can add, view, edit and delete records. Records
can be added with many information such as duration of task, name, address,
time and date. File handling has been effectively used to keep the records.

The basic user-defined functions used in this project are listed below:

 int password() – contains/manages/handles password protection


 void addrecord() – to add new diary record
 void viewrecord() – to view added record in list
 void editrecord() – to modify and update an added record
 void editpassword() – to modify/change a password
 void deleterecord() – to delete or remove a record permanently from
system file

In this project, you need to enter a password to view, edit or delete record.
Password is not required to view the main menu or to add record. We have used
password in other mini projects in Code with C; what’s little different in this
project is that you can edit the password within the application i.e., after
executing or upon running the project.
Your password is currently ‘Enter’ for this mini project. Don’t type e-n-t-e-r.
Press the Enter key!

Program :
#include<stdio.h> printf("\n\n\t\tMAIN MENU:");

#include<stdlib.h> printf("\n\n\tADD RECORD\t[1]");

#include<conio.h> printf("\n\tVIEW RECORD\t[2]");

#include<string.h> printf("\n\tEDIT RECORD\t[3]");

int password(); printf("\n\tDELETE RECORD\t[4]");

void addrecord(); printf("\n\tEDIT PASSWORD\t[5]");

void viewrecord(); printf("\n\tEXIT\t\t[6]");

void editrecord(); printf("\n\n\tENTER YOUR CHOICE:");

void editpassword(); scanf("%d",&ch);

void deleterecord(); switch(ch)

struct record {

{ case 1:

char time[6]; addrecord();

char name[30]; break;

char place[25]; case 2:

char duration[10]; viewrecord();

char note[500]; break;

}; case 3:

int main() editrecord();

{ break;

int ch; case 4:

printf("\n\n\t***********************************\n"); deleterecord();

printf("\t*PASSWORD PROTECTED PERSONAL break;


DIARY*\n");
case 5:
printf("\t***********************************");
editpassword();
while(1)
break;
{
case 6:
{
printf("\n\n\t\tTHANK YOU FOR USING THE
SOFTWARE "); fp=fopen(filename,"wb+");

getch(); if(fp==NULL)

exit(0); {

default: printf("\nSYSTEM ERROR...");

printf("\nYOU ENTERED WRONG printf("\nPRESS ANY KEY TO EXIT");


CHOICE..");
getch();
printf("\nPRESS ANY KEY TO TRY AGAIN");
return ;
getch();
}
break;
}
}
while ( another == 'Y'|| another=='y' )
system("cls");
{
}
choice=0;
return 0;
fflush(stdin);
}
printf ( "\n\tENTER TIME:[hh:mm]:");
void addrecord( )
scanf("%s",time);
{
rewind(fp);
system("cls");
while(fread(&e,sizeof(e),1,fp)==1)
FILE *fp ;
{
char another = 'Y' ,time[10];
if(strcmp(e.time,time)==0)
struct record e ;
{
char filename[15];
printf("\n\tTHE RECORD ALREADY
int choice; EXISTS.\n");

printf("\n\n\t\t***************************\n"); choice=1;

printf("\t\t* WELCOME TO THE ADD MENU *"); }

printf("\n\t\t***************************\n\n"); }

printf("\n\n\tENTER DATE OF YOUR if(choice==0)


RECORD:[yyyy-mm-dd]:");
{
fflush(stdin);
strcpy(e.time,time);
gets(filename);
printf("\tENTER NAME:");
fp = fopen (filename, "ab+" ) ;
fflush(stdin);
if ( fp == NULL )
gets(e.name);
fflush(stdin); if(choice!=0)

printf("\tENTER PLACE:"); {

gets(e.place); return ;

fflush(stdin); }

printf("\tENTER DURATION:"); do

gets(e.duration); {

fflush(stdin); printf("\n\tENTER THE DATE OF RECORD TO


BE VIEWED:[yyyy-mm-dd]:");
printf("\tNOTE:");
fflush(stdin);
gets(e.note);
gets(filename);
fwrite ( &e, sizeof ( e ), 1, fp ) ;
fpte = fopen ( filename, "rb" ) ;
printf("\nYOUR RECORD IS ADDED...\n");
if ( fpte == NULL )
}
{
printf ( "\n\tADD ANOTHER RECORD...(Y/N) " ) ;
puts ( "\nTHE RECORD DOES NOT
fflush ( stdin ) ; EXIST...\n" ) ;

another = getchar( ) ; printf("PRESS ANY KEY TO EXIT...");

} getch();

fclose ( fp ) ; return ;

printf("\n\n\tPRESS ANY KEY TO EXIT..."); }

getch(); system("cls");

} printf("\n\tHOW WOULD YOU LIKE TO


VIEW:\n");
void viewrecord( )
printf("\n\t1.WHOLE RECORD OF THE DAY.");
{
printf("\n\t2.RECORD OF FIX TIME.");
FILE *fpte ;
printf("\n\t\tENTER YOUR CHOICE:");
system("cls");
scanf("%d",&ch);
struct record customer ;
switch(ch)
char time[6],choice,filename[14];
{
int ch;
case 1:
printf("\n\n\t\t*******************************\n");
printf("\nTHE WHOLE RECORD FOR %s
printf("\t\t* HERE IS THE VIEWING MENU *"); IS:",filename);

printf("\n\t\t*******************************\n\n"); while ( fread ( &customer, sizeof ( customer ),


1, fpte ) == 1 )
choice=password();
{ printf("\nYOU TYPED SOMETHING
ELSE...\n");
printf("\n");
break;
printf("\nTIME: %s",customer.time);
}
printf("\nMEETING WITH:
%s",customer.name); printf("\n\nWOULD YOU LIKE TO CONTINUE
VIEWING...(Y/N):");
printf("\nMEETING AT:
%s",customer.place); fflush(stdin);

printf("\nDURATION: scanf("%c",&choice);
%s",customer.duration);
}
printf("\nNOTE: %s",customer.note); while(choice=='Y'||choice=='y');

printf("\n"); fclose ( fpte ) ;

} return ;

break; }

case 2: void editrecord()

fflush(stdin); {

printf("\nENTER TIME:[hh:mm]:"); system("cls");

gets(time); FILE *fpte ;

while ( fread ( &customer, sizeof ( customer ), struct record customer ;


1, fpte ) == 1 )
char time[6],choice,filename[14];
{
int num,count=0;
if(strcmp(customer.time,time)==0)
printf("\n\n\t\t*******************************\n");
{
printf("\t\t* WELCOME TO THE EDITING MENU
printf("\nYOUR RECORD IS:"); *");

printf("\nTIME: %s",customer.time); printf("\n\t\t*******************************\n\n");

printf("\nMEETING WITH: choice=password();


%s",customer.name);
if(choice!=0)
printf("\nMEETING AT:
%s",customer.place); {

printf("\nDUARATION: return ;
%s",customer.duration);
}
printf("\nNOTE: %s",customer.note);
do
}
{
}
printf("\n\tENTER THE DATE OF RECORD TO
break; BE EDITED:[yyyy-mm-dd]:");

default: fflush(stdin);
printf("\n7.GO BACK TO MAIN MENU.");
gets(filename);
do
printf("\n\tENTER TIME:[hh:mm]:");
{
gets(time);
printf("\n\tENTER YOUR CHOICE:");
fpte = fopen ( filename, "rb+" ) ;
fflush(stdin);
if ( fpte == NULL )
scanf("%d",&num);
{
fflush(stdin);
printf( "\nRECORD DOES NOT EXISTS:" ) ;
switch(num)
printf("\nPRESS ANY KEY TO GO BACK");
{
getch();
case 1:
return; printf("\nENTER THE NEW DATA:");

} printf("\nNEW TIME:[hh:mm]:");

while ( fread ( &customer, sizeof ( customer ), 1, gets(customer.time);


fpte ) == 1 )
break;
{
case 2:
if(strcmp(customer.time,time)==0) printf("\nENTER THE NEW DATA:");

{ printf("\nNEW MEETING PERSON:");

printf("\nYOUR OLD RECORD WAS AS:"); gets(customer.name);

printf("\nTIME: %s",customer.time); break;

printf("\nMEETING WITH: case 3:


%s",customer.name); printf("\nENTER THE NEW DATA:");

printf("\nMEETING AT: printf("\nNEW MEETING PLACE:");


%s",customer.place);
gets(customer.place);
printf("\nDURATION:
%s",customer.duration); break;

printf("\nNOTE: %s",customer.note); case 4:


printf("\nENTER THE NEW DATA:");
printf("\n\n\t\tWHAT WOULD YOU LIKE TO
EDIT.."); printf("\nDURATION:");

printf("\n1.TIME."); gets(customer.duration);

printf("\n2.MEETING PERSON."); break;

printf("\n3.MEETING PLACE."); case 5:


printf("ENTER THE NEW DATA:");
printf("\n4.DURATION.");
printf("\nNOTE:");
printf("\n5.NOTE.");
gets(customer.note);
printf("\n6.WHOLE RECORD.");
break;
case 6: if(choice==5)
printf("\nENTER THE NEW DATA:");
{
printf("\nNEW TIME:[hh:mm]:");
system("cls");
gets(customer.time);
printf("\n\t\tEDITING COMPLETED...\n");
printf("\nNEW MEETING PERSON:");
printf("--------------------\n");
gets(customer.name);
printf("THE NEW RECORD IS:\n");
printf("\nNEW MEETING PLACE:");
printf("--------------------\n");
gets(customer.place);
printf("\nTIME: %s",customer.time);
printf("\nDURATION:");
printf("\nMEETING WITH:
gets(customer.duration); %s",customer.name);

printf("\nNOTE:"); printf("\nMEETING AT: %s",customer.place);

gets(customer.note); printf("\nDURATION: %s",customer.duration);

break; printf("\nNOTE: %s",customer.note);

case 7: fclose(fpte);
printf("\nPRESS ANY KEY TO GO
BACK...\n"); printf("\n\n\tWOULD YOU LIKE TO EDIT
ANOTHER RECORD.(Y/N)");
getch();
scanf("%c",&choice);
return ;
count++;
break;
}
default:
printf("\nYOU TYPED SOMETHING else
ELSE...TRY AGAIN\n");
{
break;
printf("\nTHE RECORD DOES NOT
} EXIST::\n");

} printf("\nWOULD YOU LIKE TO TRY


while(num<1||num>8); AGAIN...(Y/N)");

fseek(fpte,-sizeof(customer),SEEK_CUR); scanf("%c",&choice);

fwrite(&customer,sizeof(customer),1,fpte); }

fseek(fpte,-sizeof(customer),SEEK_CUR); }
while(choice=='Y'||choice=='y');
fread(&customer,sizeof(customer),1,fpte);
fclose ( fpte ) ;
choice=5;
if(count==1)
break;
printf("\n%d FILE IS EDITED...\n",count);
}
else if(count>1)
}
printf("\n%d FILES ARE EDITED..\n",count);
i++;
else
pass[i]=getch();
printf("\nNO FILES EDITED...\n");
}
printf("\tPRESS ENTER TO EXIT EDITING
MENU."); }

getch(); pass[i]='\0';

} fpp=fopen("SE","r");

int password() if (fpp==NULL)

{ {

char pass[15]= {0},check[15]= {0},ch; printf("\nERROR WITH THE SYSTEM


FILE...[FILE MISSING]\n");
FILE *fpp;
getch();
int i=0,j;
return 1;
printf("::FOR SECURITY PURPOSE::");
}
printf("::ONLY THREE TRIALS ARE ALLOWED::");
else
for(j=0; j<3; j++)
i=0;
{
while(1)
i=0;
{
printf("\n\n\tENTER THE PASSWORD:");
ch=fgetc(fpp);
pass[0]=getch();
if(ch==EOF)
while(pass[i]!='\r')
{
{
check[i]='\0';
if(pass[i]=='\b')
break;
{
}
i--;
check[i]=ch-5;
printf("\b");
i++;
printf(" ");
}
printf("\b");
if(strcmp(pass,check)==0)
pass[i]=getch();
{
}
printf("\n\n\tACCESS GRANTED...\n");
else
return 0;
{
}
printf("*");
else getch();

{ }

printf("\n\n\tWRONG fclose(fp);
PASSWORD..\n\n\tACCESS DENIED...\n");
check=password();
}
if(check==1)
}
{
printf("\n\n\t::YOU ENTERED WRONG
PASSWORD::YOU ARE NOT ALLOWED TO return ;
ACCESS ANY FILE::\n\n\tPRESS ANY KEY TO GO
BACK..."); }

getch(); do

return 1; {

} if(check==0)

void editpassword() {

{ i=0;

system("cls"); choice=0;

printf("\n"); printf("\n\n\tENTER THE NEW


PASSWORD:");
char pass[15]= {0},confirm[15]= {0},ch;
fflush(stdin);
int choice,i,check;
pass[0]=getch();
FILE *fp;
while(pass[i]!='\r')
fp=fopen("SE","rb");
{
if(fp==NULL)
if(pass[i]=='\b')
{
{
fp=fopen("SE","wb");
i--;
if(fp==NULL)
printf("\b");
{
printf(" ");
printf("SYSTEM ERROR...");
printf("\b");
getch();
pass[i]=getch();
return ;
}
}
else
fclose(fp);
{
printf("\nSYSTEM RESTORED...\nYOUR
PASSWORD IS 'ENTER'\n PRESS ENTER TO printf("*");
CHANGE PASSWORD\n\n");
i++;
pass[i]=getch(); getch();

} return ;

} }

pass[i]='\0'; i=0;

i=0; while(pass[i]!='\0')

printf("\n\tCONFIRM PASSWORD:"); {

confirm[0]=getch(); ch=pass[i];

while(confirm[i]!='\r') putc(ch+5,fp);

{ i++;

if(confirm[i]=='\b') }

{ putc(EOF,fp);

i--; fclose(fp);

printf("\b"); }

printf(" "); else

printf("\b"); {

confirm[i]=getch(); printf("\n\tTHE NEW PASSWORD DOES


NOT MATCH.");
}
choice=1;
else
}
{
}
printf("*");
}
i++; while(choice==1);

confirm[i]=getch(); printf("\n\n\tPASSWORD CHANGED...\n\n\tPRESS


ANY KEY TO GO BACK...");
}
getch();
}
}
confirm[i]='\0';
void deleterecord( )
if(strcmp(pass,confirm)==0)
{
{
system("cls");
fp=fopen("SE","wb");
FILE *fp,*fptr ;
if(fp==NULL)
struct record file ;
{
char filename[15],another = 'Y' ,time[10];;
printf("\n\t\tSYSTEM ERROR");
int choice,check;
getch();
printf("\n\n\t\t*************************\n");
return ;
printf("\t\t* WELCOME TO DELETE MENU*");
}
printf("\n\t\t*************************\n\n");
fclose(fp);
check = password();
remove(filename);
if(check==1)
printf("\nDELETED SUCCESFULLY...");
{
break;
return ;
case 2:
}
printf("\n\tENTER THE DATE OF
while ( another == 'Y' ) RECORD:[yyyy-mm-dd]:");

{ fflush(stdin);

printf("\n\n\tHOW WOULD YOU LIKE TO gets(filename);


DELETE.");
fp = fopen (filename, "rb" ) ;
printf("\n\n\t#DELETE WHOLE
RECORD\t\t\t[1]"); if ( fp == NULL )

printf("\n\t#DELETE A PARTICULAR RECORD {


BY TIME\t[2]");
printf("\nTHE FILE DOES NOT EXISTS");
do
printf("\nPRESS ANY KEY TO GO
{ BACK.");

printf("\n\t\tENTER YOU CHOICE:"); getch();

scanf("%d",&choice); return ;

switch(choice) }

{ fptr=fopen("temp","wb");

case 1: if(fptr==NULL)

printf("\n\tENTER THE DATE OF RECORD {


TO BE DELETED:[yyyy-mm-dd]:");
printf("\nSYSTEM ERROR");
fflush(stdin);
printf("\nPRESS ANY KEY TO GO
gets(filename); BACK");

fp = fopen (filename, "wb" ) ; getch();

if ( fp == NULL ) return ;

{ }

printf("\nTHE FILE DOES NOT EXISTS"); printf("\n\tENTER THE TIME OF RECORD


TO BE DELETED:[hh:mm]:");
printf("\nPRESS ANY KEY TO GO
BACK."); fflush(stdin);
gets(time);

while(fread(&file,sizeof(file),1,fp)==1)

if(strcmp(file.time,time)!=0)

fwrite(&file,sizeof(file),1,fptr);

fclose(fp);

fclose(fptr);

remove(filename);

rename("temp",filename);

printf("\nDELETED SUCCESFULLY...");

break;

default:

printf("\n\tYOU ENTERED WRONG


CHOICE");

break;

}
while(choice<1||choice>2);

printf("\n\tDO YOU LIKE TO DELETE ANOTHER


RECORD.(Y/N):");

fflush(stdin);

scanf("%c",&another);

printf("\n\n\tPRESS ANY KEY TO EXIT...");

getch();

}
OUTPUT:

S-ar putea să vă placă și