password protected diary

57
PASSWORD PROTECTED PERSONAL DIARY SHARDA SHARAN REG. NO. - 1015574 NIPS College of IT & Management

Upload: sharda-sharan

Post on 24-Jan-2017

134 views

Category:

Education


1 download

TRANSCRIPT

Page 1: Password protected diary

PASSWORD PROTECTED

PERSONAL DIARY

SHARDA SHARAN

REG. NO. - 1015574

NIPS College of IT & Management

Page 2: Password protected diary

INDEXING

BACKGROUND

GENERAL THEORY

ALGORITHM

OUTPUT

DISUSSION

SUMMARY

REFRENCE

Page 3: Password protected diary

Background

For technical students, the most important factor to measure their ability and skill is their

practical performance rather than their theoretical knowledge. Considering this fact, this

mini-project is included in our lab assignment to prepare a project using C language in

order to develop their practical ability to develop programs and software using c

programming language.

In this project our project topic PERSONAL DAIRY SYSTEM .In this programm stores

the data related about book record in any dairy .So this program can be used as personal

dairy system.

To build the project, it took us nearly one week. The project required vast knowledge of

use of structure and data file which are two important and complex features of C

programming language. We got help from senior student and teachers in lab. Rest, we

consulted various books on c programming that turned out to be more than useful in gaining

concepts of computer programming.

After gaining the useful concepts, we started the project on modular level. Each of our team

members shared equal load by writing different parts of the program such as different user-

defined functions. We would devote about 2 hour time each day during the college days

and worked throughout the day during holidays.

After the program was successfully written, compiled and tested for syntactic and logical

errors in about one week, we had then to prepare the remaining parts of the project such

as discussion and other theoretical part. This kind of working as a team and working hard

marked the completion of the project.

Objectives:-

1. To learn about different dairy functions included in different header files.

2. To learn about the use of user defined function, structure, array and data file in C.

3. To learn to be able to develop complex programs aimed at solving particular task

in practical field as per users requirements.

4. To be able to work in group as a team sharing different responsibilities

Page 4: Password protected diary

General Theory

This project is based on high level language i.e. c programming. In this project we use

important parts of c programming which are control statement, looping, function, array,

structure, pointer, data file.

C programming language:

c is structured programming based computer programming language was developed by

Dennis Ritchie at Bell laboratories in 1972.Structured programming refers to programming

that produce program with clean flow, clear and a degree of modularity or hierarchical

structure is a simple, contained, versatile, excellent, efficient, fast general purpose

language. It has high degree of language of C is a function oriented additional task

including input and output, graphics, math computation and access to peripheral devices

are placed as library function.

Control Statement:

Logical operation is carried out by several symmetrical or logical statements. There are

two types of control statement based on their function.

Selective structure:

Selective structures are used when we have a number of situations where we need to change

the order of execution of statements based on certain condition. The selective statements

make a decision to take the right path before changing the order of execution. C provides

the following statements for selective structure:

if statements

switch statements

if statements:

The if statement is a powerful decision making statement and it is used to control the flow

of execution of statements. It is a two way statement and is used in conjunction with an

expression.

Page 5: Password protected diary

If statement allows the computer to evaluate the expression first and then on depending

whether the value of the expression is true or false it transfer the control to the particular

statement. At this point of the program has two paths to follow: one for true condition and

other for false condition. The types of if statements are explained below:

Simple if statement:

The simple if statement is used to conditionally excite a block of code based on whether a

test condition is true or false. If the condition is true the block of code is executed, otherwise

it is skipped. The syntax of if statement is given below:

if(test expression

{

statement-block;

}

statement-x;

if else statement

The if else statement extends the idea of the if statement by specifying another section of

code that should be executed only if the condition is false i.e. conditional branching. True-

block statements are to be executed only if the test expression is true and false block

statements to be executed only if the condition is false. The syntax of if else statement is

given below:

if(test expression)

{

true block statement;

}

else

{

Page 6: Password protected diary

false block statement;

}

The switch statement:

c has built in multi way decision statement known as switch. It successively test the value

of an expression against a list of case values (integer or character consonants).when a match

is found the statement associated with that case is executed. The syntax of switch

expression is given below:

switch(expression)

{

case constant-1:

block-1;

break;

case constant-2:

block-2;

break;

………….

………….

case constant-2:

block-n;

break;

default:

default statement;

}

Page 7: Password protected diary

Looping:

Loop caused a section of code to be repeated for a specified number of times or until some

condition holds true. When a condition becomes false, the loop terminates and control

passes to statement below loop. Different types of loops are discussed below with their

major characteristics and syntax used in C:

While loop:

The while loop specifies that a section of code should be executed while a certain condition

holds true. The syntax of while loop is given below:

while(test expression)

{

body of loop;

(

statements block);

}

do while statement:

the do while statement is very similar to while statement. It also specifies that a section of

code should be executed while a certain condition holds true. the difference between while

and do while loop is that while loop test its condition at the top of its loop but do while

loop tests its condition at the bottom of loop. In while loop, if the test condition is false,

the block of code is skipped. Since condition is tested at the bottom of loop in do while

loop, its block of code is always executed at least once. The syntax of do while loop is

given below:

do

{

Page 8: Password protected diary

body of loop

}while (test expression);

For loop:

generally an assignment statement used to set loop control variable. Test expression is a

relational expression that determines when loop exits. Update expression defines how the

loop variable the for loop is used to execute a block of code for a fixed number of

repetitions. Initialization is changes each time when the loop is repeated. The syntax of for

loop is given below:

for(initialization expression;test expression;update expression)

{

body of loop;

}

break statement:

The break statement is used to jump out of loop. The break statement terminates the

execution of the nearest enclosing loop. Control passes to the statement that follows the

terminated statement. in a switch break statement causes the program to execute the next

statement after switch.

break;

Function:

Every c program consists of one or functions. Execution of program always begins by

carrying out instruction in main. Function makes program significantly easier to understand

and maintain. A well written function may be reused in multiple programs. Program that

are easier to design, debug and maintain A function is a self contained program segment

that carries out some specific well defined task..

Page 9: Password protected diary

Return statement:

A function may or may not send back any value to the calling function. If it does, it is

through return statement. The called function can only return only one value per call at

most. The syntax of return statement is given below:

Return;

Pointer:

A pointer is a variable that represents the location (rather than value) of a data item, such

as a variable or an array element. Pointers can be used to pass information back and forth

between a function and a reference point. Pointer provides a way to return multiple data

items from a function via function argument. When a pointer variable is declared, the

variable name must be preceded by an aesteric (*).the syntax of a pointer declaration is:

data type *ptar;

Structure:

It is a heterogeneous user defined data type. It is also called constructed data type. It may

contain different data types .Structure can also store non homogenous data type into a

single collection. Structure may contain pointet, arrays, or even other structures other than

the common data types such as int, float, long int etc. A structure provides a means of

grouping variables under a single name for easier handling and identification. It can be

defined as new named types. It is a convenient way of grouping several pieces of related

information together. Complex hierarchies can be created by nesting structures. Structures

may be copied to and assigned. They are also useful in passing groups of logically related

data into structures. The declaration of structures is given below:

struct tag

{

member 1;

member 2;

member n;

};

Page 10: Password protected diary

DATA FILE

When accessing files through C, the first necessity is to have a way to access the files.

For C File I/O that needs to be used is a FILE pointer, which will let the program keep

track of the file being accessed. (Just as the memory address of the file or the location of

the file).

For example:

FILE *fp;

Where, FILE (uppercase letters required) is a special structure that establishes the buffer

area, and ‘fp’ is a pointer variable that indicates the beginning of the buffer area. It is

defined within a system include file, stdio.h. The pointer fp is often referred to as a

stream pointer, or simply a stream.

To open a file we need to use the fopen function, which returns a FILE pointer. Once a

file is opened, we can use the FILE pointer to let the compiler perform input and output

functions on the file.

FILE *fopen(const char *filename, const char *mode);

where, filename is a string that represents the name of the data file.

The modes are as follows:

r - open for reading

w - open for writing (file need not exist)

a - open for appending (file need not exist)

r+ - open for reading and writing, start at beginning

w+ - open for reading and writing (overwrite file)

a+ - open for reading and writing (append if file exists)

Page 11: Password protected diary

Note that it's possible for fopen to fail even if the program is perfectly correct: it might try

to open a file specified by the user, and that file might not exist (or it might be write-

protected). In those cases, fopen will return 0, the NULL pointer.

Here's a simple example of using fopen:

FILE *fp;

fp = fopen(“file.txt”.”r”);

This code will open file.txt for reading in text mode. To open a file in a binary mode we

must add ‘b’ to the end of the mode string; for example, "rb" (for the reading and writing

modes, we can add the b either after the plus sign - "r+b" - or before - "rb+")

To close a function fclose can use the function

fclose(fp);

fclose returns zero if the file is closed successfully.

remove() is used to rename a file and rename() is used to rename an existing file.

int remove(filename)

int rename(old filename, new filename)

Binary I/O

For binary File I/O we use fread and fwrite to read and write into the data file.

The declarations for each are similar:

Page 12: Password protected diary

size_t fread(void *ptr, size_t size_of_elements, size_t number_of_elements, FILE

*a_file);

size_t fwrite(const void *ptr, size_t size_of_elements, size _t number_of_elements, FILE

*a_file);

Both of these functions deal with blocks of memories - usually arrays. Because they

accept pointers, we can also use these functions with other data structures; you can even

write structs to a file or a read struct into memory.

fread takes four arguments. The declaration of a void *ptr; void means that it is a pointer

that can be used for any type variable. The first argument is the name of the array or the

address of the structure you want to write to the file. The second argument is the size of

each element of the array; it is in bytes. For example, if we have an array of characters

and want to read it in one byte, so size_of_elements is one. You can use the sizeof

operator to get the size of the various datatypes; for example, if we have a variable int x;

you can get the size of x with sizeof(x);. This usage works even for structs or arrays. Eg,

if we have a variable of a struct type with the name a_struct, we can use sizeof(a_struct)

to find out how much memory it is taking up.

e.g.,

sizeof(int);

The third argument is simply how many elements we want to read or write; for example,

if we pass a 100 element array, we want to read no more than 100 elements, so we pass in

100.

The final argument is simply the file pointer we've been using. When fread is used, after

being passed an array, fread will read from the file until it has filled the array, and it will

return the number of elements actually read. If the file, for example, is only 30 bytes, but

we try to read 100 bytes, it will return that it read 30 bytes. To check to ensure the end of

file was reached, use the feof function, which accepts a FILE pointer and returns true if

the end of the file has been reached.

fwrite: is similar in usage, except instead of reading into the memory, it writes from

memory into a file.

Page 13: Password protected diary

fseek: Repositions the file pointer of a stream.

Declaration: int fseek(FILE *stream, long offset, int whence);

Remarks: fseek sets the file pointer associated with a stream to a new position.

stream : -Stream whose file pointer fseek sets.

offset: - Difference in bytes between whence (a file pointer position) and new position.

For text mode streams, offset should be 0 or a value returned by ftell.

whence : - One of three SEEK_xxx file pointer locations (0(SET), 1(CUR), or 2(END)).

fseek is used with stream I/O.

rewind is similar to fseek but it can reposition the stream pointer to the beginning

only.

void rewind(stream);

The above statement is equivalent to fseek(stream, 0L, SEEK_SET)

fflush flushes a stream.

int fflush(*stream);

fflush returns 0 if the buffer was successfully flushed. The value 0 is also returned

in cases in which the specified stream has no buffer or is open for reading only. A return

value of EOF indicates an error.

Page 14: Password protected diary

ALGORITHM

1. Start

2. Declare

main( ) function:

Step 1:start.

Step 2:declare variable choice as integer and check as char.

Step 3:personalize the main menu.

Step 4:creat a while loop.

Step 4.1:display menu item and ask to enter choice

Step 4.2:get the value of the choice

Step 4.3:check the value of choice by using switch case and perform the task as

Step 4.3.1:if ch is 1 then call function addrecord ( )

ch is 2 then call function view record( )

ch is 3 then call function editrecord( )

ch is 4 then call function deleterecord( )

ch is 5 then call function editpassword( )

ch is 6 then call function exit( )

Step 5:stop

addrecord( ) function

Step 1:start.

Step 2:declare file pointer f and variables test as char type .

Step 3:open the file in append and write mode

Step 4:if file cannot open then exit

Step 5 else enter the records

Step 6:get the person record

Page 15: Password protected diary

Step 7:write to the file.

Step 8: if want to escape press esc key and goto main menu

Step8.1 else enter other records

Step 9:close that file.

Step 9+.stop.

viewrecord( ) function

Step 1:start.

Step 2:declare file pointer f ,

Step 3:open the file in read mode.

Step 3.1:if the file doesnot exist exit

Step 4 display records

Step 5 for exit press esc & goto main menu.

Step 7:close that file.

Step 8.stop.

deleterecord( ) function

Step 1:start.

Step 2:declare file pointer fp and fptr ,variables as another=‘y’,time[10],filename[15] are

character type,choice ,check as integer type and declare file as structure with

variable,time,name, place, duration and note as character type.

Step 3:call the paswword( ) function.

Step 4:ask user to enter choice(1or2).

Step 4.1:if choice is 1,delete the whole record of the entered date.

Page 16: Password protected diary

Step 4.2:if choice is 2,delete the specific record.

Step 4.2.1:ask the date.

Step 4.2.2 : open file of that date if it exists goto step 4.2.3 otherwise goto

step 4.3.

Step 4.2.3:ask the time from user.

Step 4.2.4 : read file of that time if it exists delete record of that time

otherwise show that entered time is invalid.

Step 4.3: if he wants to delete another record goto step 4 otherwise goto main menu.

Step 5: close that file.

Step 6:stop.

editpassword( ) FUNCTION BODY

Step 1.start

Step 2. declare file pointer fp,pass[15]={0},confirm[15]={0} as character type and

i,check,choice as an integer type.

Srep 3.initialize check=password( )i.e call the function.

Step 4.if check=1,exit and view main menu otherwise goto step 5.

Step 5.get one password from user and store it in variable pass.

Step 6.get the password from the user and store it in variable confirm for confirmation.

Step 7.compare the two string pass and confirm.

Step 7.1.if the value returned is zero(0) then open the file fp and save password in it

and display the message “password is changed“and enter any key to goto

main menu.

Step 7.2.if value returned is not zero(0) then display “the new password doesnot

match” and goto main menu.

Step 8.stop.

Page 17: Password protected diary

editrecord() FUNCTION BODY:

Step1: clear the screen and declare a file pointer, character array as filename and time,

character choice, integer num and count. assign count =0;

Step2: print the statement “WELCOME TO THE EDITING MENU”,

Step3: call the function password,

Step4: if the return value is not equal to zero return back to main,

Step5: otherwise, in the do loop, read the filename and time,

Step6: open the filename in read mode, if file pointer returns zero display error message

and return back to main,

Step7: otherwise, read the file by size of structure and store in it,

Step8: every time it stores, compare the structure’s time variable with time variable,

Step9: if not equal read another structure form the file,

Step10: otherwise, display the structure as old record and ask for the value of num,

Step10.1.If num=1, read the value of time of structure,

Step10.2.If num=2, read the value of name of structure,

Step10.3.If num=3, read the value of place of structure,

Step10.4.If num=4, read the value of duration of structure,

Step10.5.If num=5, read the value of note of structure,

Step10.6.If num=6, read the whole structure,

Step10.7.If num=7, return back to main,

Step10.8.If num= other then 1 to 7, display error message,

Step11: rewind the pointer to the top of that record and write the fresh structure,

Step12: assign choice =5, increase the value of count by one,

Step13: if no similar structure’s time and time are found go out of the loop without

assigning choice =5,

Step14: if choice =5 then read and display the new record,

Page 18: Password protected diary

Step15: read the value of choice,

Step16: if choice= ‘y’ or ‘Y’ then goto step5, otherwise goto step 17,

Step17: display the value of count,

Step18: return back to main,

Step19: end

Page 19: Password protected diary

SOURCE CODE:

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

#include<string.h>

int password();

void addrecord();

void viewrecord();

void editrecord();

void editpassword();

void deleterecord();

struct record

{

char time[6];

char name[30];

char place[25];

char duration[10];

char note[500];

} ;

void main()

Page 20: Password protected diary

{

int ch;

clrscr();

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

printf("\t*PASSWORD PROTECTED PERSONAL DIARY*\n");

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

while(1)

{

printf("\n\n\t\tMAIN MENU:");

printf("\n\n\tADD RECORD\t[1]");

printf("\n\tVIEW RECORD\t[2]");

printf("\n\tEDIT RECORD\t[3]");

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

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

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

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

scanf("%d",&ch);

switch(ch)

{

case 1:

Page 21: Password protected diary

addrecord();

break;

case 2:

viewrecord();

break;

case 3:

editrecord();

break;

case 4:

deleterecord();

break;

case 5:

editpassword();

break;

case 6:

printf("\n\n\t\tTHANK YOU FOR USING THE

SOFTWARE BY:\n\n\t\TSHARDA SHARAN SAHU...");

getch();

exit(0);

Page 22: Password protected diary

default:

printf("\nYOU ENTERED WRONG CHOICE..");

printf("\nPRESS ANY KEY TO TRY AGAIN");

getch();

break;

}

system("cls");

}

}

void addrecord( )

{

FILE *fp ;

char another = 'Y' ,time[10];

struct record e ;

char filename[15];

int choice;

system("cls");

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

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

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

Page 23: Password protected diary

printf("\n\n\tENTER DATE OF YOUR RECORD:[yyyy-mm-dd]:");

fflush(stdin);

gets(filename);

fp = fopen (filename, "ab+" ) ;

if ( fp == NULL )

{

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

if(fp==NULL)

{

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

printf("\nPRESS ANY KEY TO EXIT");

getch();

return ;

}

}

while ( another == 'Y'|| another=='y' )

{

choice=0;

fflush(stdin);

printf ( "\n\tENTER TIME:[hh:mm]:");

scanf("%s",time);

Page 24: Password protected diary

rewind(fp);

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

{

if(strcmp(e.time,time)==0)

{

printf("\n\tTHE RECORD ALREADY EXISTS.\n");

choice=1;

}

}

if(choice==0)

{

strcpy(e.time,time);

printf("\tENTER NAME:");

fflush(stdin);

gets(e.name);

fflush(stdin);

printf("\tENTER PLACE:");

gets(e.place);

fflush(stdin);

printf("\tENTER DURATION:");

gets(e.duration);

fflush(stdin);

printf("\tNOTE:");

Page 25: Password protected diary

gets(e.note);

fwrite ( &e, sizeof ( e ), 1, fp ) ;

printf("\nYOUR RECORD IS ADDED...\n");

}

printf ( "\n\tADD ANOTHER RECORD...(Y/N) " ) ;

fflush ( stdin ) ;

another = getchar( ) ;

}

fclose ( fp ) ;

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

getch();

}

void viewrecord( )

{

struct record customer ;

char time[6],choice,filename[14];

int ch;

FILE *fpte ;

system("cls");

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

Page 26: Password protected diary

printf("\t\t* HERE IS THE VIEWING MENU *");

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

choice=password();

if(choice!=0)

{

return ;

}

do

{

printf("\n\tENTER THE DATE OF RECORD TO BE

VIEWED:[yyyy-mm-dd]:");

fflush(stdin);

gets(filename);

fpte = fopen ( filename, "rb" ) ;

if ( fpte == NULL )

{

puts ( "\nTHE RECORD DOES NOT EXIST...\n" ) ;

printf("PRESS ANY KEY TO EXIT...");

getch();

return ;

}

system("cls");

printf("\n\tHOW WOULD YOU LIKE TO VIEW:\n");

Page 27: Password protected diary

printf("\n\t1.WHOLE RECORD OF THE DAY.");

printf("\n\t2.RECORD OF FIX TIME.");

printf("\n\t\tENTER YOUR CHOICE:");

scanf("%d",&ch);

switch(ch)

{

case 1:

printf("\nTHE WHOLE RECORD FOR %s IS:",filename);

while ( fread ( &customer, sizeof ( customer ), 1, fpte ) == 1 )

{

printf("\n");

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

printf("\nMEETING WITH: %s",customer.name);

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

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

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

printf("\n");

}

break;

case 2:

fflush(stdin);

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

Page 28: Password protected diary

gets(time);

while ( fread ( &customer, sizeof ( customer ), 1, fpte ) == 1 )

{

if(strcmp(customer.time,time)==0)

{

printf("\nYOUR RECORD IS:");

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

printf("\nMEETING WITH: %s",customer.name);

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

printf("\nDUARATION: %s",customer.duration);

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

}

}

break;

default: printf("\nYOU TYPED SOMETHING ELSE...\n");

break;

}

printf("\n\nWOULD YOU LIKE TO CONTINUE VIEWING...(Y/N):");

fflush(stdin);

scanf("%c",&choice);

Page 29: Password protected diary

}while(choice=='Y'||choice=='y');

fclose ( fpte ) ;

return ;

}

void editrecord()

{

FILE *fpte ;

struct record customer ;

char time[6],choice,filename[14];

int num,count=0;

system("cls");

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

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

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

choice=password();

if(choice!=0)

{

return ;

}

do

{

printf("\n\tENTER THE DATE OF RECORD TO BE EDITED:[yyyy-

mm-dd]:");

fflush(stdin);

Page 30: Password protected diary

gets(filename);

printf("\n\tENTER TIME:[hh:mm]:");

gets(time);

fpte = fopen ( filename, "rb+" ) ;

if ( fpte == NULL )

{

printf( "\nRECORD DOES NOT EXISTS:" ) ;

printf("\nPRESS ANY KEY TO GO BACK");

getch();

return;

}

while ( fread ( &customer, sizeof ( customer ), 1, fpte ) == 1 )

{

if(strcmp(customer.time,time)==0)

{

printf("\nYOUR OLD RECORD WAS AS:");

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

printf("\nMEETING WITH: %s",customer.name);

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

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

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

printf("\n\n\t\tWHAT WOULD YOU LIKE TO EDIT..");

printf("\n1.TIME.");

Page 31: Password protected diary

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

printf("\n3.MEETING PLACE.");

printf("\n4.DURATION.");

printf("\n5.NOTE.");

printf("\n6.WHOLE RECORD.");

printf("\n7.GO BACK TO MAIN MENU.");

do

{

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

fflush(stdin);

scanf("%d",&num);

fflush(stdin);

switch(num)

{

case 1: printf("\nENTER THE NEW DATA:");

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

gets(customer.time);

break;

case 2: printf("\nENTER THE NEW DATA:");

printf("\nNEW MEETING PERSON:");

gets(customer.name);

break;

Page 32: Password protected diary

case 3: printf("\nENTER THE NEW DATA:");

printf("\nNEW MEETING PLACE:");

gets(customer.place);

break;

case 4: printf("\nENTER THE NEW DATA:");

printf("\nDURATION:");

gets(customer.duration);

break;

case 5: printf("ENTER THE NEW DATA:");

printf("\nNOTE:");

gets(customer.note);

break;

case 6: printf("\nENTER THE NEW DATA:");

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

gets(customer.time);

printf("\nNEW MEETING PERSON:");

gets(customer.name);

printf("\nNEW MEETING PLACE:");

gets(customer.place);

printf("\nDURATION:");

Page 33: Password protected diary

gets(customer.duration);

printf("\nNOTE:");

gets(customer.note);

break;

case 7: printf("\nPRESS ANY KEY TO GO

BACK...\n");

getch();

return ;

//break;

default: printf("\nYOU TYPED SOMETHING

ELSE...TRY AGAIN\n");

break;

}

}while(num<1||num>8);

fseek(fpte,-sizeof(customer),SEEK_CUR);

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

fseek(fpte,-sizeof(customer),SEEK_CUR);

fread(&customer,sizeof(customer),1,fpte);

choice=5;

break;

}

Page 34: Password protected diary

}

if(choice==5)

{

system("cls");

printf("\n\t\tEDITING COMPLETED...\n");

printf("--------------------\n");

printf("THE NEW RECORD IS:\n");

printf("--------------------\n");

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

printf("\nMEETING WITH: %s",customer.name);

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

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

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

fclose(fpte);

printf("\n\n\tWOULD YOU LIKE TO EDIT ANOTHER

RECORD.(Y/N)");

scanf("%c",&choice);

count++;

}

else

{

printf("\nTHE RECORD DOES NOT EXIST::\n");

printf("\nWOULD YOU LIKE TO TRY AGAIN...(Y/N)");

scanf("%c",&choice);

Page 35: Password protected diary

}

}while(choice=='Y'||choice=='y');

fclose ( fpte ) ;

if(count==1)

printf("\n%d FILE IS EDITED...\n",count);

else if(count>1)

printf("\n%d FILES ARE EDITED..\n",count);

else

printf("\nNO FILES EDITED...\n");

printf("\tPRESS ENTER TO EXIT EDITING MENU.");

getch();

}

int password()

{

char pass[15]={0},check[15]={0},ch;

FILE *fpp;

int i=0,j;

printf("::FOR SECURITY PURPOSE::");

printf("::ONLY THREE TRIALS ARE ALLOWED::");

for(j=0;j<3;j++)

{

Page 36: Password protected diary

i=0;

printf("\n\n\tENTER THE PASSWORD:");

pass[0]=getch();

while(pass[i]!='\r')

{

if(pass[i]=='\b')

{

i--;

printf("\b");

printf(" ");

printf("\b");

pass[i]=getch();

}

else

{

printf("*");

i++;

pass[i]=getch();

}

}

pass[i]='\0';

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

if (fpp==NULL)

Page 37: Password protected diary

{

printf("\nERROR WITH THE SYSTEM FILE...[FILE

MISSING]\n");

getch();

return 1;

}

else

i=0;

while(1)

{

ch=fgetc(fpp);

if(ch==EOF)

{

check[i]='\0';

break;

}

check[i]=ch-5;

i++;

}

if(strcmp(pass,check)==0)

{

printf("\n\n\tACCESS GRANTED...\n");

return 0;

}

Page 38: Password protected diary

else

{

printf("\n\n\tWRONG PASSWORD..\n\n\tACCESS

DENIED...\n");

}

}

printf("\n\n\t::YOU ENTERED WRONG PASSWORD::YOU ARE NOT

ALLOWED TO ACCESS ANY FILE::\n\n\tPRESS ANY KEY TO GO

BACK...");

getch();

return 1;

}

void editpassword()

{

char pass[15]={0},confirm[15]={0},ch;

int choice,i,check;

FILE *fp;

system("cls");

printf("\n");

fp=fopen("SE","rb");

if(fp==NULL)

{

fp=fopen("SE","wb");

if(fp==NULL)

Page 39: Password protected diary

{

printf("SYSTEM ERROR...");

getch();

return ;

}

fclose(fp);

printf("\nSYSTEM RESTORED...\nYOUR PASSWORD IS 'ENTER'\n

PRESS ENTER TO CHANGE PASSWORD\n\n");

getch();

}

fclose(fp);

check=password();

if(check==1)

{

return ;

}

do

{

if(check==0)

{

i=0;

choice=0;

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

fflush(stdin);

Page 40: Password protected diary

pass[0]=getch();

while(pass[i]!='\r')

{

if(pass[i]=='\b')

{

i--;

printf("\b");

printf(" ");

printf("\b");

pass[i]=getch();

}

else

{

printf("*");

i++;

pass[i]=getch();

}

}

pass[i]='\0';

i=0;

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

confirm[0]=getch();

while(confirm[i]!='\r')

Page 41: Password protected diary

{

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

{

i--;

printf("\b");

printf(" ");

printf("\b");

confirm[i]=getch();

}

else

{

printf("*");

i++;

confirm[i]=getch();

}

}

confirm[i]='\0';

if(strcmp(pass,confirm)==0)

{

fp=fopen("SE","wb");

if(fp==NULL)

{

printf("\n\t\tSYSTEM ERROR");

Page 42: Password protected diary

getch();

return ;

}

i=0;

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

{

ch=pass[i];

putc(ch+5,fp);

i++;

}

putc(EOF,fp);

fclose(fp);

}

else

{

printf("\n\tTHE NEW PASSWORD DOES NOT MATCH.");

choice=1;

}

}

}while(choice==1);

Page 43: Password protected diary

printf("\n\n\tPASSWORD CHANGED...\n\n\tPRESS ANY KEY TO GO

BACK...");

getch();

}

void deleterecord( )

{

struct record file ;

char filename[15],another = 'Y' ,time[10];

int choice,check;

FILE *fp,*fptr ;

system("cls");

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

printf("\t\t* WELCOME TO DELETE MENU*");

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

check = password();

if(check==1)

{

return ;

}

while ( another == 'Y' )

{

Page 44: Password protected diary

printf("\n\n\tHOW WOULD YOU LIKE TO DELETE.");

printf("\n\n\t#DELETE WHOLE RECORD\t\t\t[1]");

printf("\n\t#DELETE A PARTICULAR RECORD BY TIME\t[2]");

do

{

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

scanf("%d",&choice);

switch(choice)

{

case 1:

printf("\n\tENTER THE DATE OF RECORD TO BE

DELETED:[yyyy-mm-dd]:");

fflush(stdin);

gets(filename);

fp = fopen (filename, "wb" ) ;

if ( fp == NULL )

{

printf("\nTHE FILE DOES NOT EXISTS");

printf("\nPRESS ANY KEY TO GO BACK.");

getch();

return ;

}

Page 45: Password protected diary

fclose(fp);

remove(filename);

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

break;

case 2:

printf("\n\tENTER THE DATE OF RECORD:[yyyy-mm-dd]:");

fflush(stdin);

gets(filename);

fp = fopen (filename, "rb" ) ;

if ( fp == NULL )

{

printf("\nTHE FILE DOES NOT EXISTS");

printf("\nPRESS ANY KEY TO GO BACK.");

getch();

return ;

}

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

if(fptr==NULL)

{

printf("\nSYSTEM ERROR");

printf("\nPRESS ANY KEY TO GO BACK");

Page 46: Password protected diary

getch();

return ;

}

printf("\n\tENTER THE TIME OF RECORD TO BE

DELETED:[hh:mm]:");

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);

Page 47: Password protected diary

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();

}

Page 48: Password protected diary

OUTPUT:

Page 49: Password protected diary
Page 50: Password protected diary
Page 51: Password protected diary
Page 52: Password protected diary
Page 53: Password protected diary
Page 54: Password protected diary
Page 55: Password protected diary

DISCUSSION:

During the project compilation, we face different problems on individual handling

of tasks.

The first problem was on the edit menu. The file search was not working properly

due to unarranged stored structure on file. This was solved by going step to step

debugging. Another problem was with view menu. The specific viewing of a record

by time was not working; it was also the same search problem. This was solved by

group discussion. Another problem was with confirming password option; the

function was not working properly. Password change function was a challenge to us.

Searching different books and surfing internet at last kept us with solution. So

solving through group effort was proved to be more efficient.

In this way, we completed our project successfully.

Page 56: Password protected diary

SUMMARY

Our main aim in this program is to prepare book record in library .The class modules

and problems through done on the computers itself were much theoretical than

practical because they were unable to teach us there application in our daily life.

The mini project on the other hand not only taught us practical use of program but

also helped us in gaining skills like co-ordination, leadership, management of time,

planning, foresights, etc. Above all it taught us that we could do something useful

with c-programming. It gave taste of being a programmer which will very useful in

our future.

Thus we can predict that we succeeded on our aim .The problems we faced make us

more confident in C language.

Page 57: Password protected diary

Refrence

Balagurusamy .E., Programming In ANSI C, the Tata McGraw-Hill

Companies, 8th Edition, 2008.

Kanetkar Yashavant, Let Us C, BPB Publication, 9th Edition, 2009.

Gottfriend, Baryon S, Schaum’s outlines Programming With C, the Tata

McGraw-Hill, 2007.

www.google.com

www.sourcecodesworld.com

www.cprogramming.com