Cn you please tell me what Im doing wrong as its not working properly
Code:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<windows.h>
#include<string.h>
#include<time.h>
#define EXIT o;
//structure to hold all info, final program will contain structures of main meal, snacks
//and also deserts, using this structure
struct database {
char prod[60];
float cal;
float carb;
float prot;
float fat;
};
//function prototypes
int full_screen(void);//puts the dos console to full screen when called
void main_menu(void);
void about_opt(void);
void help_opt(void);
void fflushstdin( void );//clears scanf when called
void clrscr(void); //clears the screen when called
FILE *fp;
struct database *point1;
int main()
{
full_screen(); //Puts the dos console into full screen when program is executed
struct database mainm[10];
main_menu();
char buf[BUFSIZ];
char *p;
int i;
int x;
FILE *fp;
for ( i = 0; i < 10; i++)
{
printf("\nAnother? (Y/N) ");
if(getch() == 'n') break;
printf("\nEnter the product:");
fgets(mainm[i].prod, 60, stdin);
if ((p = strchr(mainm[i].prod, '\n')) != NULL)
*p = '\0';
system("cls");
printf("\nNow Please Enter The Nutritional Information:");
printf("\nEnter cal:");
scanf("%f", &mainm[i].cal);
fflushstdin();
printf("\nEnter carb:");
scanf("%f", &mainm[i].carb);
fflushstdin();
printf("\nEnter protein:");
scanf("%f", &mainm[i].prot);
fflushstdin();
printf("\nEnter fat:");
scanf("%f", &mainm[i].fat);
system("cls");
fflushstdin();
}
fp = fopen("output.dat", "ab");
fwrite(mainm, 1, sizeof(struct database) * 10, fp);
fclose(fp);
fp = fopen("output.dat", "rb");
fread (mainm, 1, sizeof(struct database) * 10, fp);
fclose(fp);
int a;
for ( a = 0; a <10; a ++)
{
clrscr();
printf("\n * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
printf("\n\nThe nutritional values for ");
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(h, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
printf("%s", mainm[a].prod);
SetConsoleTextAttribute ( h, wOldColorAttrs);
printf(" item # %d are:",a);
printf("\n\nCALORIES - ");
SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
printf("%f", mainm[a].cal);
SetConsoleTextAttribute ( h, wOldColorAttrs);
printf("\n\nCARBOHYDRATES - ");
SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
printf("%f", mainm[a].carb);
SetConsoleTextAttribute ( h, wOldColorAttrs);
printf("\n\nPROTEIN - ");
SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
printf("%f", mainm[a].prot);
SetConsoleTextAttribute ( h, wOldColorAttrs);
printf("\n\nFAT - ");
SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
printf("%f\n\n", mainm[a].prot);
SetConsoleTextAttribute ( h, wOldColorAttrs);
printf("\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
printf("\n\nPress return for next product...");
getch();
}
}