Wednesday, June 27, 2012

School Project Personal Diary Management in C programming

This project is similar to the project Contact Management in C. In this project, I am reusing all the code from it. I created this Personal Diary Management project just by renaming printed messages, adding a few functions, and modifying existing functions slightly.

Please go through the Contact Management project if you haven't. In this project, I have explained the techniques of file handling in C.

So, in this project, I will explain the changes that I have made.

Let's start with describing data structure.
// Define Constant Variables
#define ESC 27
#define REF_SZ 10
#define DATE_SZ 64
#define MIN_TEXT_SZ 50
#define MAX_TEST_SZ 500
#define READ_ARRAY_SZ 15
#define DATA_FILE "dataFile.dat"
#define TEMP_FILE "tempFile.dat"

//Define data structure

struct data{
    char refNum[REF_SZ]; //Unique reference number and auto-incremented
    char noteDate[DATE_SZ]; //Auto populated using system date and time
    char eventDate[DATE_SZ]; //Event date
    char location[MIN_TEXT_SZ]; //Location of event happened
    char eventDesc[MIN_TEXT_SZ]; //Event short description
    char notes[MAX_TEST_SZ]; //Notes of the Event
};
I am using 6 variables in a structure. The variable "refNum" will be unique and it is auto-increment. The variable "noteDate" is to store note added date and it is also auto-populated using system date and time. 

Other variables are:
  • eventDate: Event date. It can be any format chosen by the user
  • location: Location of event happened.
  • eventDesc: Event short description.
  • notes: Notes of the event. Maximum character is 500.
Although the variable refNum is auto-incremented, I haven't defined it as an integer. Rather than storing number value only, I decided to add '#R' as an initial character so that the unique reference value will look like "#R10001" instead of "1000".

To achieve this we have to create two separate small functions which I will describe below.

Function: getNextRef()
//Get next reference number

int getNextRef(){

    struct data a;
    int num=0;
    fp = fopen(DATA_FILE,"rb");

    if(fp!= NULL){

        fseek(fp,0,SEEK_END);

        fseek(fp,ftell(fp)-sizeof(a),0);
        fread(&a,sizeof(a),1,fp);

        // converting string to number
        for (int i = 0; a.refNum[i + 2] != '\0'; i++) {
            num = num * 10 + (a.refNum[i + 2] - 48);
        }
        fclose(fp);
        return num;

    } else {

        return 10000;
    }
}
This function will read the last item from the file and read the reference number which is the previous reference number and also the highest value. It will remove the first two characters, convert the remaining numbers into an integer data type, and return it. This function will be executed at the start of the application so if it does not find a file then it will return 1000. 

Function: calRefNum(char *buff, int num)
//Calculate next reference number
static void calRefNum(char *buff, int num){

    char tmpRef[REF_SZ];
    char refNum[REF_SZ] = {'#','R'};
    sprintf(tmpRef,"%d",num);
    strcat(refNum, tmpRef);
    strcpy(buff,refNum);
}
This function converts the reference number into char data type, concatenates with the "#R" initial character, and assigns it to a character pointer which is used while adding notes.

Apart from these changes I have made a few changes in readData(), add(), and view() functions. Once you compile and run it you will understand the changes.

Please download the source code from the GitHub Download Source Code.

You can also watch a video about this project on YouTube.


28 comments:

  1. hey u never mentioned the password

    ReplyDelete
    Replies
    1. u dun need tht part at all guys....jus delete the password part completely......as simple as tht :) ty guys anyways

      Delete
    2. sir passwd plz pawanvannal1993@gmail.com

      Delete
    3. sir passwd plz pawanvannal1993@gmail.com

      Delete
    4. do you even programmer just enter !

      Delete
  2. Screen shots of outputs would have made this more useful .

    ReplyDelete
  3. i am using turbo c please send me a copy.my email id is akshkshay@gmail.com thanks.

    ReplyDelete
  4. hey i got some syntax error when some one wants to delete record then
    it will directly delete record without checking condition

    ReplyDelete
  5. What is the password????

    ReplyDelete
  6. FRIEND PLEASE GIVE ME THE PASSWORD.TOMORROW I NEED TO SUBMIT MY PROJECT PLEASE PLEASE

    ReplyDelete
  7. I NEED PASSWORD PLZ PLZ PLZ SND ME

    ReplyDelete
  8. please send me password rakeshfzk@gmail.com

    ReplyDelete
  9. it has no password all you need to do is ENTER

    ReplyDelete
  10. The info stored in the file shows the data entered by user correctly but that which is already written like "Enter name:" appears in weird shapes in the file. Why is that so?

    ReplyDelete
  11. Any way to remove the Microsoft thing copy right ?

    ReplyDelete
  12. pls give me the written abstract for personal diary management

    ReplyDelete
  13. just prees "Enter" button on the computer keyboard

    ReplyDelete
  14. this project has lot of errors

    ReplyDelete
  15. firstly i thnx to admin for thisproject ...admin i use this project in this i want some modification as in date and time i want that this project get current date and time in this project i need it plz help me plz i really needs your help plz help me my emailid is minnisharma399@gmail.com u can also mail me plz i wait your rply plz

    ReplyDelete
  16. thanks guys for this open source code

    ReplyDelete
  17. Thanks for your valuable posting about Dairy software it was very informative.

    ReplyDelete
  18. this is differant project i am enjoyed the project thank you

    ReplyDelete
  19. Programmer to be https://goo.gl/FA26WS

    ReplyDelete
  20. Wondering if you can send me an edited code so that instead of saying personal diary, it says work diary and remove the place bit of the code, as I don't require this. Also could you make it so it changes the date layout to dd/mm/yyyy as thats the right way to read dates.
    (Sorry from the UK) :)

    ReplyDelete