I'm trying to create an array of a struct, which I have done and I have to receive an input from the user. The first piece of data would be the description (a string). I have to allocate memory for it as well. I'm not how big the string is going to be to I want to check as it's going in, but I don't think I've set it up right. Can anyone give me a hint or a page I can look at to figure it out?
Greatly appreciated. Here are the important snipits of code:
struct myExpenses
{
char *description;
float cost;
};
int main (void)
{
struct myExpenses *pData = NULL;
struct myExpenses expenses[60];
int exit=0;
int i = 0;
char buffer[81] = "";
printf("Please enter all your descriptions:\n");
for (i=0;i < 60; i++)
{
fgets(buffer,stdin);
expenses[i].description=(char *)malloc sizeof(buffer);
}