Code:
#include<stddef.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
/*definition*/
#define LCHAR 1000000000
#define LINESIZE 512
/*variable declarations*/
int p;
int j;
char input;
char authenticate[LINESIZE];
char buff[LINESIZE];
char f[LINESIZE];
char password[LINESIZE];
char username[LINESIZE];
char userpassword[LINESIZE];
char verified[LINESIZE];
/*file pointers*/
FILE *log;
FILE *verify;
FILE *change;
FILE *BasicNeeds;
FILE *TransactionBills;
FILE *Transportation;
FILE *EmergencyNeeds;
FILE *OtherExpenses;
/*prototypes*/
void access();
void login();
void changePassword();
void newPassword();
void tracker();
void add();
void remove();
void view();
void time();
void addBasicNeeds();
void addTransactionBills();
void addTransportation();
void addEmergencyNeeds();
void addOtherExpenses();
/*structure definition*/
struct particulars {
char *entry;
int cost;
char *period;
};
int main() {
while (j !=4) {
printf("\n\n\n");
printf("\t\t||||||||||||WELCOME TO EXPENSE TRACKER||||||||||||");
printf("\n\n\n");
printf("\t\t\t\[1] Create an account\n");
printf("\t\t\t\[2] Access an account\n");
printf("\t\t\t\[3] Change user password\n");
printf("\t\t\t\[4] Exit\n\n");
printf("\t\t||||||||||||||||||||||||||||||||||||||||||||||||||\n\n");
printf("\t\t\tSelect an option: ");
scanf("%d", &j);
switch(j){
case 1:{
access();
break;
}
case 2:{
login();
break;
}
case 3:{
changePassword();
break;
}
case 4:{
break;
}
default:
printf("\n\t\tNo such choice.\n");
break;
}
}
return 0;
}
/*create account*/
void access() {
if ((log = fopen ("access.txt","w+")) == NULL) {
printf("Incorrect login.\n");
}
else {
printf("\n\n");
printf("\t\t||||||||||||||||||||||||||||||||||||||||||||||||||\n\n");
printf("\t\tUSERNAME: ");
scanf("%s", username);
printf("\t\tPASSWORD: ");
scanf("%s", userpassword);
fputs(username, log);
fputs(" ", log);
fputs(userpassword, log);
printf("\n\t\tRegistration successful.\n\n");
fclose (log);
}
}
/*access acount*/
void login() {
if ((verify = fopen ("access.txt","r+")) == NULL) {
printf("Incorrect login.\n\n");
}
else {
printf("\n\n\n");
printf("\t\tUSERNAME:");
scanf("%s", verified);
printf("\t\tPASSWORD:");
scanf("%s", password);
fscanf(verify, "%s%s", authenticate, userpassword);
if((strcmp(verified,authenticate)==0) &&(strcmp(userpassword, password)==0)) {
printf("\n\n\n\n");
printf("\t\tLogin successful.\n", verified);
tracker();
}
else {
printf("\n\n\t\tIncorrect username or password.\n\n", verified);
}
}
}
/*change password*/
void changePassword(){
if ((verify = fopen ("access.txt","r+")) == NULL) {
printf("Incorrect login.\n\n");
}
else {
printf("\n\n\n");
printf("\t\tUSERNAME:");
scanf("%s", verified);
printf("\t\tPASSWORD:");
scanf("%s", password);
fscanf(verify, "%s%s", authenticate, userpassword);
if((strcmp(verified,authenticate)==0) &&(strcmp(userpassword, password)==0)) {
printf("\n\n\n\n");
printf("\t\tLogin successful.\n", verified);
newPassword();
}
else {
printf("\n\n\t\tIncorrect username or password.\n\n", verified);
}
}
}
/*new password*/
void newPassword(){
if ((change = fopen ("access.txt","w+")) == NULL) {
printf("Incorrect login.\n\n");
}
else {
printf("\n\n\n");
printf("\t\tUSERNAME:");
scanf("%s", verified);
printf("\t\tNEW PASSWORD:");
scanf("%s", userpassword);
fscanf(change, "%s%s", authenticate, userpassword);
fputs(username, change);
fputs(" ", change);
fputs(userpassword, change);
printf("\n\t\tChange successful.\n\n");
fclose (change);
}
}
/*program*/
void tracker() {
while (j !=4) {
printf("\n\n\n");
printf("\t\t|||||||||||||||||EXPENSE TRACKER||||||||||||||||||");
printf("\n\n\n");
printf("\t\t[1] Add items\n");
printf("\t\t[2] Remove items\n");
printf("\t\t[3] View items\n");
printf("\t\t[4] Exit\n\n");
printf("\t\t||||||||||||||||||||||||||||||||||||||||||||||||||\n\n");
printf("\t\t\tSelect an option: ");
scanf("%d", &j);
switch (j) {
case 1:{
add();
break;
}
case 2:{
remove();
break;
}
case 3:{
view();
break;
}
case 4: {
break;
}
default:
printf("\n\t\tNo such choice.\n\n");
break;
}
}
}
/*add items*/
void add() {
time_t rawtime;
struct tm * timeinfo;
char buffer [100];
char particulars [LINESIZE];
while (j !=6) {
printf("\n\n\n");
printf("\t\t|||||||||||||||||EXPENSE TRACKER||||||||||||||||||");
printf("\n\n\n");
printf("\t\t[1] Basic Needs\n");
printf("\t\t[2] Transaction Bills\n");
printf("\t\t[3] Transportation\n");
printf("\t\t[4] Emergency Needs\n");
printf("\t\t[5] Other expenses\n");
printf("\t\t[6] Exit\n\n");
printf("\t\t||||||||||||||||||||||||||||||||||||||||||||||||||\n\n");
printf("\t\t\tSelect an option: ");
scanf("%d", &j);
switch (j) {
case 1:{
addBasicNeeds();
break;
}
case 2:{
addTransactionBills();
break;
}
case 3:{
addTransportation();
break;
}
case 4:{
addEmergencyNeeds();
break;
}
case 5: {
addOtherExpenses();
break;
}
case 6:
break;
default: printf("\n\t\tNo such choice.\n\n");
break;
}
}
}
/*system time*/
void time() {
time_t rawtime;
struct tm * timeinfo;
char buffer [100];
time (&rawtime);
timeinfo = localtime (&rawtime);
strftime (buffer,100,"%I:%M%p %x.",timeinfo);
puts (buffer);
}
/*add items to specific categories*/
void addBasicNeeds() {
int item;
int t;
time_t rawtime;
struct tm * timeinfo;
char buffer [100];
particulars particulars [LINESIZE];
if((BasicNeeds = fopen("bneeds.txt", "a+")) == NULL) {
printf("Cannot open file. Please try again.");
}
else {
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,100,"%I:%M%p %x.",timeinfo);
particulars[p].entry = f;
particulars[p].cost = item;
particulars[p].period = buffer;
printf("\n\t\tInput ENTRY [space] COST:\n");
printf("\n\t\tConsider entries as one word input.\n");
scanf("%s", &f);
scanf("%d", &item);
for(p=0 ; p<1 ; p++) {
fprintf(BasicNeeds, " You've just added %s ", f);
fprintf(BasicNeeds, " which costs P %d. Recorded %s.\n", item, buffer);
}
while(feof(BasicNeeds)) {
input = getc(BasicNeeds);
printf("%c", input);
}
rewind(BasicNeeds);
}
fclose(BasicNeeds);
}
void addTransactionBills() {
int item;
int t;
time_t rawtime;
struct tm * timeinfo;
char buffer [100];
particulars particulars [LINESIZE];
if((TransactionBills = fopen("tbills.txt", "a+")) == NULL) {
printf("Cannot open file. Please try again.");
}
else {
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,100,"%I:%M%p %x.",timeinfo);
particulars[p].entry = f;
particulars[p].cost = item;
particulars[p].period = buffer;
printf("\n\t\tInput ENTRY [space] COST:\n");
printf("\n\t\tConsider entries as one word input.\n");
scanf("%s", &f);
scanf("%d", &item);
for(p=0 ; p<1 ; p++) {
fprintf(TransactionBills, " You've just added %s ", f);
fprintf(TransactionBills, " which costs P %d. Recorded %s.\n", item, buffer);
}
while(feof(TransactionBills)) {
input = getc(TransactionBills);
printf("%c", input);
}
rewind(TransactionBills);
}
fclose(TransactionBills);
}
void addTransportation() {
int item;
time_t rawtime;
struct tm * timeinfo;
char buffer [100];
particulars particulars [LINESIZE];
if((Transportation = fopen("trans.txt", "a+")) == NULL) {
printf("Cannot open file. Please try again.");
}
else {
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,100,"%I:%M%p %x.",timeinfo);
particulars[p].entry = f;
particulars[p].cost = item;
particulars[p].period = buffer;
printf("\n\t\tInput ENTRY [space] COST:\n");
printf("\n\t\tConsider entries as one word input.\n");
scanf("%s", &f);
scanf("%d", &item);
for(p=0 ; p<1 ; p++) {
fprintf(Transportation, " You've just added %s ", f);
fprintf(Transportation, " which costs P %d. Recorded %s.\n", item, buffer);
}
while(feof(Transportation)) {
input = getc(Transportation);
printf("%c", input);
}
rewind(Transportation);
}
fclose(Transportation);
}
void addEmergencyNeeds() {
int item;
time_t rawtime;
struct tm * timeinfo;
char buffer [100];
particulars particulars[LINESIZE];
if((EmergencyNeeds = fopen("eneeds.txt", "a+")) == NULL) {
printf("Cannot open file. Please try again.");
}
else {
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,100,"%I:%M%p %x.",timeinfo);
particulars[p].entry = f;
particulars[p].cost = item;
particulars[p].period = buffer;
printf("\n\t\tInput ENTRY [space] COST:\n");
printf("\n\t\tConsider entries as one word input.\n");
scanf("%s", f);
scanf("%d", &item);
for(p=0 ; p<1 ; p++) {
fprintf(EmergencyNeeds, " You've just added %s ", f);
fprintf(EmergencyNeeds, " which costs P %d. Recorded %s.\n", item, buffer);
}
while(feof(EmergencyNeeds)) {
input = getc(EmergencyNeeds);
printf("%c", input);
}
rewind(EmergencyNeeds);
}
fclose(EmergencyNeeds);
}
void addOtherExpenses() {
int item;
time_t rawtime;
struct tm * timeinfo;
char buffer [100];
particulars particulars [LINESIZE];
if((OtherExpenses = fopen("other.txt", "a+")) == NULL) {
printf("Cannot open file. Please try again.");
}
else {
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,100,"%I:%M%p %x.",timeinfo);
particulars[p].entry = f;
particulars[p].cost = item;
particulars[p].period = buffer;
printf("\n\t\tInput ENTRY [space] COST:\n");
printf("\n\t\tConsider entries as one word input.\n");
scanf("%s", &f);
scanf("%d", &item);
for(p=0 ; p<1 ; p++) {
fprintf(OtherExpenses, " You've just added %s ", f);
fprintf(OtherExpenses, " which costs P %d. Recorded %s.\n", item, buffer);
}
while(feof(OtherExpenses)) {
input = getc(OtherExpenses);
printf("%c", input);
}
rewind(OtherExpenses);
}
fclose(OtherExpenses);
}
/*view items*/
void view() {
while (j !=6) {
printf("\n\n\n");
printf("\t\t|||||||||||||||||EXPENSE TRACKER||||||||||||||||||");
printf("\n\n\n");
printf("\t\t[1] Basic Needs\n");
printf("\t\t[2] Transaction Bills\n");
printf("\t\t[3] Transportation\n");
printf("\t\t[4] Emergency Needs\n");
printf("\t\t[5] Other expenses\n");
printf("\t\t[6] Exit\n\n");
printf("\t\t*****Category that doesn't load may be empty.*****\n");
printf("\t\t||||||||||||||||||||||||||||||||||||||||||||||||||\n\n");
printf("\t\t\tSelect an option: ");
scanf("%d", &j);
switch (j) {
case 1:{
if((BasicNeeds = fopen("bneeds.txt", "r")) == NULL) {
printf("Cannot open file. Please try again.");
}
else{
while(fgets(buff, LCHAR, BasicNeeds)){
printf("%s",buff);
}
}
fclose(BasicNeeds);
break;
}
case 2:{
if((TransactionBills = fopen("tbills.txt", "r")) == NULL) {
printf("Cannot open file. Please try again.");
}
else{
while(fgets(buff, LCHAR, TransactionBills)){
printf("%s",buff);
}
}
fclose(TransactionBills);
break;
}
case 3:{
if((Transportation = fopen("trans.txt", "r")) == NULL) {
printf("Cannot open file. Please try again.");
}
else{
while(fgets(buff, LCHAR, Transportation)){
printf("%s",buff);
}
}
fclose(Transportation);
break;
}
case 4:{
if((EmergencyNeeds = fopen("eneeds.txt", "r")) == NULL) {
printf("Cannot open file. Please try again.");
}
else{
while(fgets(buff, LCHAR, EmergencyNeeds)){
printf("%s",buff);
}
}
fclose(EmergencyNeeds);
break;
}
case 5: {
if((OtherExpenses = fopen("other.txt", "r")) == NULL) {
printf("Cannot open file. Please try again.");
}
else{
while(fgets(buff, LCHAR, OtherExpenses)){
printf("%s",buff);
}
}
fclose(OtherExpenses);
break;
}
case 6:{
break;
}
default:
printf ("\n\t\tNo such choice.\n\n");
break;
}
}
}
/*remove items*/
void remove() {
while (j !=6) {
printf("\n\n\n");
printf("\t\t|||||||||||||||||EXPENSE TRACKER||||||||||||||||||");
printf("\n\n\n");
printf("\t\t[1] Basic Needs\n");
printf("\t\t[2] Transaction Bills\n");
printf("\t\t[3] Transportation\n");
printf("\t\t[4] Emergency Needs\n");
printf("\t\t[5] Other expenses\n");
printf("\t\t[6] Exit\n\n");
printf("\t\t||||||||||||||||||||||||||||||||||||||||||||||||||\n\n");
printf("\t\t\tSelect an option: ");
scanf("%d", &j);
switch (j) {
case 1: {
if((BasicNeeds = fopen("bneeds.txt", "w")) == NULL) {
printf("Cannot open file. Please try again.");
}
else {
printf("\n\t\tDeletion successful.\n\n");
}
fclose(BasicNeeds);
break;
}
case 2:{
if((TransactionBills = fopen("tbills.txt", "w")) == NULL) {
printf("Cannot open file. Please try again.");
}
else {
printf("\n\t\tDeletion successful.\n\n");
}
fclose(TransactionBills);
break;
}
case 3:{
if((Transportation = fopen("trans.txt", "w")) == NULL) {
printf("Cannot open file. Please try again.");
}
else{
printf("\n\t\tDeletion successful.\n\n");
}
fclose(Transportation);
break;
}
case 4:{
if((EmergencyNeeds = fopen("eneeds.txt", "w")) == NULL) {
printf("Cannot open file. Please try again.");
}
else{
printf("\n\t\tDeletion successful.\n\n");
}
fclose(EmergencyNeeds);
break;
}
case 5: {
if((OtherExpenses = fopen("other.txt", "w")) == NULL) {
printf("Cannot open file. Please try again..");
}
else{
printf("\n\t\tDeletion successful.\n\n");
}
fclose(OtherExpenses);
break;
}
case 6:{
break;
}
default: printf ("\n\t\tNo such choice.\n\n");
break;
}
}
}