This example does what you want, and you can create as many instance of add as you want.
I limit your loop to run once and have tested that the code works with visual studio 2019:
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#define DAY_SIZ 20
#define DATE_SIZ 40
#define TIME_SIZ 20
#define PLACE_SIZ 120
#define DATA_SIZ (BUFSIZ - 1)
struct add
{
char day[DAY_SIZ];
char date[DATE_SIZ];
char time[TIME_SIZ];
char place[PLACE_SIZ];
char data[DATA_SIZ];
};
struct add* create_add_struct() {
struct add* rec;
rec = (struct add*)malloc(sizeof(struct add));
return rec;
}
void destroy_add_struct(struct add* rec) {
free(rec);
}
void clear_add_struct(struct add* rec) {
memset(rec->day, 0, sizeof(rec->day));
memset(rec->date, 0, sizeof(rec->date));
memset(rec->time, 0, sizeof(rec->time));
memset(rec->place, 0, sizeof(rec->place));
memset(rec->data, 0, sizeof(rec->data));
}
void get_text_from_user(const char prompt[], char *txt, int siz) {
char buf[BUFSIZ];
printf("%s", prompt);
fgets(buf, BUFSIZ, stdin);
memcpy(txt, buf, siz);
}
void fill_add_struct(struct add* rec) {
printf("Do not enter any lines longer than %d\n\n", BUFSIZ);
get_text_from_user("Enter Day:", rec->day, sizeof(rec->day) - 1);
get_text_from_user("Enter Date:", rec->date, sizeof(rec->date) - 1);
get_text_from_user("Enter Time:", rec->time, sizeof(rec->time) - 1);
get_text_from_user("Enter Place:", rec->place, sizeof(rec->place) - 1);
get_text_from_user("Tell me about your day:", rec->data, sizeof(rec->data) - 1);
}
void print_add_struct(struct add* rec) {
printf("\n\n\n");
printf("Day : %s\n", rec->day);
printf("Date : %s\n", rec->date);
printf("Time : %s\n", rec->time);
printf("Place: %s\n", rec->place);
printf("Data : %s\n\n\n", rec->data);
}
int main()
{
// The number of times we want the loop to run
int i = 1;
// Collect data from the user and print it
while (i-- != 0)
{
// Allocate memory and initialize it
struct add* rec = create_add_struct();
clear_add_struct(rec);
// Get data from the user and print it
fill_add_struct(rec);
print_add_struct(rec);
// Release memory
destroy_add_struct(rec);
}
// Return success
return 0;
}
The reason I allocate your structure, is to make sure a stack-overflow does not occur, no pun intended.
If you want to create 365 add structs, you can create them like so:
struct add **records;
records = (struct add **) malloc(sizeof(struct add *) * 365);
for(int idx = 0; idx < 365; ++idx) {
records[idx] = create_add_struct();
clear_add_struct(records[idx]);
/* ... insert code ... */
}
/* ... insert code ... */
// Free memory
for(int idx = 0; idx < 365; ++idx) {
destroy_add_struct(records[idx]);
}
free(records);
I have not tested if the last piece of code compiles and works. Again I use malloc() and free() to avoid a stack-overflow.