home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: OtherApp / OtherApp.zip / nut-os2.zip / src / prtmenu.c < prev    next >
C/C++ Source or Header  |  1998-09-10  |  2KB  |  74 lines

  1. /* prtmenu.c */
  2.  
  3. /*
  4.     Nut nutrition software 
  5.     Copyright (C) 1998 Jim Jozwiak.
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #include "prtmenu.h"
  23. #include "food.h"
  24. #include "util.h"
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28.  
  29. void print_menus()
  30. {
  31. FILE *fp;
  32. struct food *meal_ptr = &meal_root;
  33. int firstpage = 1;
  34. char last_meal_date[7], last_meal = '0';
  35. if (meal_ptr->next == NULL)
  36.  {
  37.  header("NUT:  Print Menus from Meal Database");
  38.  spacer(0);
  39.  printf("\nThere are no meals in database.  Press <enter> to continue..."); 
  40.  firstpage = get_int();
  41.  return;
  42.  }
  43. if ((fp = fopen("nut.menus","w")) == NULL)
  44.  {
  45.  printf("Can't open file \"nut.menus\" to write.\n");
  46.  printf("Press <enter> to continue...");
  47.  firstpage = get_int();
  48.  return;
  49.  }
  50. strcpy(last_meal_date,"");
  51. while (meal_ptr->next != NULL)
  52.  {
  53.  meal_ptr = meal_ptr->next;
  54.  if (strcmp(last_meal_date,meal_ptr->meal_date) != 0 || last_meal != meal_ptr->meal)
  55.   {
  56.   strcpy(last_meal_date,meal_ptr->meal_date);
  57.   last_meal = meal_ptr->meal;
  58.   if (firstpage == 1)
  59.    {
  60.    firstpage = 0;
  61.    fprintf(fp,"Meal Date:  %s                                               Meal Number:  %d\n\n",last_meal_date,last_meal);
  62.    } 
  63.   else fprintf(fp,"\nMeal Date:  %s                                               Meal Number:  %d\n\n",last_meal_date,last_meal);
  64.   }
  65.  fprintf(fp,"%4.0f gm or %4.1f oz %-60s\n",meal_ptr->grams,meal_ptr->grams / 28.35,meal_ptr->name);
  66.  }
  67. fclose(fp);
  68. header("NUT:  Print Menus from Meal Database");
  69. spacer(0);
  70. printf("\nMenus printed to \"nut.menus\".  Press <enter> to continue..."); 
  71. firstpage = get_int();
  72. return;
  73. }
  74.