Expense Managar Using LL
Expense Managar Using LL
h>
#include <stdlib.h>
#include <string.h>
#define N 50
#define M 30
double currentincome = 0;
double currentexpense = 0;
struct node
char date[M];
double amount;
char category[N];
struct record
double x, y;
} *point = NULL;
double b;
if (fopen("Record.bin", "rb") != NULL) /*first time it will give null bcoz there is no file name
record.bin,therefor it will not take income
and expense from file,assign value will be displayed i.e 0,0..after creating income and
expense first time
will be create and again when user runs program then this if will execute and take
income and expense from file*/
{
point = readrecord();
currentincome = point->x;
currentexpense = point->y;
}
if (fopen("myincome.bin", "rb") != NULL) /*it means file is already created and some data is
already there,and we have to get that and create
linked list,address of first node will be in income pointer. step bcoz if we dont
do this than
after closing terminal if we create inome and saved it than previous data will be
deletedand it
overrtites in file...after doing this income will point to first node and all data will
be come in ram
{
income = readincome(income);
}
{
expense = readexpense(expense);
}
do
{
printf(" |_______________________________________________\n");
printf("5.EXIT\n");
scanf("%d", &option);
printf("\n\n\n");
switch (option)
{
case 1:
scanf("%s %s %s", s1, s2, s3); //gets,fgets and other functions are not working thats why these
stepes have done
strcpy(a, "");
strcat(a, s1);
strcat(a, s2);
strcat(a, s3);
scanf("%lf", &b);
scanf("%s", c);
currentincome = currentincome + b;
create(a, b, c, &income);
writeincome(income);
break;
case 2:
strcpy(a, "");
strcat(a, s1);
strcat(a, s2);
strcat(a, s3);
scanf("%lf", &b);
scanf("%s", c);
currentexpense = currentexpense + b;
create(a, b, c, &expense);
writeexpense(expense);
break;
case 3:
display(3);
break;
case 4:
display(4);
break;
case 5:
point->x = currentincome;
point->y = currentexpense;
write(point);
break;
default:
break;
}
return 0;
void create(char x[], double y, char z[], struct node **temp) /* it isokay to write *temp if we pass
only income rather than &income*/
{
if (*temp == NULL)
{
strcpy(newnode->date, x);
newnode->amount = y;
strcpy(newnode->category, z);
newnode->next = NULL;
*temp = newnode;
}
else
{
ptr = *temp;
{
ptr = ptr->next;
}
strcpy(newnode->date, x);
newnode->amount = y;
strcpy(newnode->category, z);
newnode->next = NULL;
ptr->next = newnode;
}
holdme = freeme->next;
free(freeme);
freeme = holdme;
}
if (ptr == NULL)
{
ptr->next = NULL;
}
else
{
{
ptr1 = ptr1->next;
}
ptr1->next = ptr2;
ptr2->next = NULL;
}
return ptr;
}
struct node *readincome(struct node *ptr)
FILE *fpointer;
if (fpointer != NULL)
{
deleterecord(ptr);
ptr = NULL;
fseek(fpointer, 0, SEEK_END);
rewind(fpointer);
{
}
}
else
{
}
return ptr;
{
if (fopen("myincome.bin", "rb") == NULL) /*if user try to view record when there is no any
record,i.e when user runs program
{
printf("____________________________________________________________________________
____________________________________\n\n");
}
else
{
//income=readincome(income);
{
ptr2 = ptr2->next;
}
printf("____________________________________________________________________________
____________________________________\n\n");
}
}
else if (a3 == 4) //if case 4 is executed then we have to print expenese record
{
if (fopen("myexpense.bin", "rb") == NULL) /*if user try to view record when there is no any
record,i.e when user runs program
printf("____________________________________________________________________________
____________________________________\n\n");
}
else
{
// expense=readexpense(expense);
{
ptr2 = ptr2->next;
}
printf("____________________________________________________________________________
____________________________________\n\n");
}
}
FILE *fpointer;
if (fpointer != NULL)
{
{
holdnext = ptr1->next;
ptr1->next = NULL;
fseek(fpointer, 0, SEEK_END);
fwrite(ptr1, sizeof(struct node), 1, fpointer); /*everytime we write into file,it will overwrite
the data...... whole data will be deleted and new data willl be written
intofile*/
ptr1->next = holdnext;
holdnext = NULL;
ptr1 = ptr1->next;
}
fclose(fpointer);
fpointer = NULL;
printf("____________________________________________________________________________
____________________________________\n\n");
}
else
{
printf("____________________________________________________________________________
____________________________________\n\n");
}
FILE *fpointer;
if (fpointer != NULL)
{
{
holdnext = ptr1->next;
ptr1->next = NULL;
fseek(fpointer, 0, SEEK_END);
fwrite(ptr1, sizeof(struct node), 1, fpointer); /*everytime we write into file,it will overwrite
the data.....
whole data will be deleted and new data willl be written intofile*/
ptr1->next = holdnext;
holdnext = NULL;
ptr1 = ptr1->next;
}
fclose(fpointer);
fpointer = NULL;
printf("____________________________________________________________________________
____________________________________\n\n");
}
else
{
printf("____________________________________________________________________________
____________________________________\n\n");
}
{
FILE *fpointer;
if (fpointer != NULL)
{
deleterecord(ptr);
ptr = NULL;
fseek(fpointer, 0, SEEK_END);
rewind(fpointer);
{
}
}
else
{
}
return ptr;
FILE *fpointer;
if (fpointer != NULL)
{
fseek(fpointer, 0, SEEK_END);
fwrite(point, sizeof(struct record), 1, fpointer); /*everytime we write into file,it will overwrite
the data.....
whole data will be deleted and new data willl be written intofile*/
}
else
{
printf("FILEOPEN ERROR\n");
}
fclose(fpointer);
fpointer = NULL;
FILE *fpointer;
if (fpointer != NULL)
{
fseek(fpointer, 0, SEEK_SET);
}
else
{
}
return ptr;
}