Code:
// Program to log weight to text file
// written by Jamie Morrissey 5/30/18
#include <stdio.h>
#include <stdlib.h>
struct myStruct {
int day;
int month;
int year;
float pounds;
};
FILE * fptr;
main()
{
struct myStruct weight[5];
fptr = fopen("my_weight.txt", "a+");
if(fptr == 0)
{
printf("Error! File not found!\n");
exit (1);
}
int i;
for(i=0;i<1;i++)
{
printf("Enter date (MM/DD/YY): ");
scanf("%d/%d/%d", &weight[i].month, &weight[i].day, &weight[i].year);
printf("Enter your weight in pounds: ");
scanf("%f", &weight[i].pounds);
}
fprintf(fptr, "Here is your weight: ");
// fseek();
for(i=0;i<1;i++)
{
fprintf(fptr, "%d/%d/%d - %.1f\n", weight[i].month, weight[i].day, weight[i].year, weight[i].pounds);
}
fclose(fptr);
return 0;
}
Well, here's the final program, i gave up on the function part and didn't use another function besides main(). I am happy i am picking it up after reading a book for about 4 months.