Thanks so much for the response!!! It's really appreciated!!
Ok, unfortunately, I really don't know what I'm doing, this is my first semester of C and I've never done any other programming. So here are the changes that I got from that.
First, global. I added the strings library, I took out the pointers.
Code:
#include <strings.h>
#include <stdio.h>
#include "banklog.h"
#define ph 10
#define max 1024
typedef struct banklog{
double amount;
const char category[ph];
const char date[ph];
const char description;
} bl;
int at = 0;//placeholder for the current struct
Here is the add function, I switched out the brackets, it's not actually working, but is this closer to what I should use to get this stored to memory? This is what I had to begin with but couldn't figure out where I was going wrong and switched it out for the brackets.
Code:
/*
Add a record to the bank log with the specified information.
Return value:
0 -- successfully added
-1 -- unable to allocate space for new entry
*/
int BANKLOGadd(double amount, const char* category, const char* date, const char* description)
{
struct banklog b[max];
if (amount!=0 && category != 0 && date != 0 && description != 0)
{
b[at].amount=amount;
strcpy (&b[at].category, category);
strcpy (&b[at].date, date);
strcpy(&b[at].description,description);
printf("Implement BANKLOGadd: %.2lf %8s %8s s\n",amount, category, date, description);
at++;
return 0;
}
return -1;
}
print basically stays the same here.
Code:
void BANKLOGprint()
{
struct banklog log[max];
// printf("Implement BANKLOGprint!\n");
int i=0;
for (i=i; i<at; i++)
{
printf("%8.2lf ",log[i].amount);
printf("%s ",log[i].category);
printf("%.*s ", log[i].date+2-1);
printf("%.20s\n", log[i].description);
}
}
I don't understand why, if it's a global, I can't access it directly in the functions. I know it's not working, but i don't totally get why.
Code:
bl[at].amount=amount;
strcpy (bl[at].category, category);
strcpy (bl[at].date, date);
strcpy(bl[at].description,description);
Thanks again for the help!