Advanced C Question

This is a discussion on Advanced C Question within the C Programming forums, part of the General Programming Boards category; There is just one last problem. When i compile the code with Turbo C 2.01 from Microsoft Corp i get ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    8

    Advanced C Question

    There is just one last problem. When i compile the code with Turbo C 2.01 from Microsoft Corp i get the 2 errors. They occur at
    line 19 & 44 : Argument list syntax error
    . This is for the void printrestaurant(). What's going on? Some help here please...

    Here's the code:
    Code:
    /* Array Of Structures containing Restaurant Details */
    # include <stdio.h>
    # include <stdlib.h>
    # include <ctype.h>
    # include <conio.h>
    # include <string.h>
    
    #define N_restaurant 5
    char target[20];
     int n,j;
    struct restaurant_t {
      char Name [100];
      char address[30];
      double av_cost;
      char food_type[20];
    
    } restaurants [N_restaurant];
    
    void printrestaurant (restaurant_t restaurant);
    void sort();
    
    int main ()
    {
      char buffer [50];
    
      for (n=0; n<N_restaurant; n++)
      {
        printf("Enter Restaurant Name: ");
        gets (restaurants[n].Name);
    	printf("Enter Address: ");
        gets (restaurants[n].address);
    	printf("Enter Food Type: ");
        gets (restaurants[n].food_type);
    	printf("Enter Cost: ");
        gets (buffer);
        restaurants[n].av_cost = atof (buffer);
      }
      printf ("\nYou have entered these restaurant:\n");
    
    sort ();
    return 0;
    }
    
    void printrestaurant(restaurant_t restaurant)
    {
    	if (strcmp(target,restaurant.food_type)==0)
    	{
    	printf ("Restaurant Name=");
    	printf ("%s\n",restaurant.Name);
    	printf ("Address=");
    	printf ("%s\n",restaurant.address);
    	printf ("Food Type=");					
    	printf ("%s\n",restaurant.food_type);
    	printf ("Cost=");					
    	printf ("%.2f\n",restaurant.av_cost);
    	}
    }
    
    void sort ()
    {
     char tName [100];
      char taddress[30];
      double tav_cost;
      char tfood_type[20];
    
      for (n=0; n<(N_restaurant-1); n++)
    	    for (j=n+1; j<N_restaurant; j++)
    			if (restaurants[n].av_cost>restaurants[j].av_cost)
    		{
    			strcpy (tName,restaurants[n].Name);
    			strcpy (restaurants[n].Name,restaurants[j].Name);
    			strcpy (restaurants[j].Name,tName);
    
    			strcpy (taddress,restaurants[n].address);
    			strcpy (restaurants[n].address,restaurants[j].address);
    			strcpy (restaurants[j].address,taddress);
    
    			strcpy (tfood_type,restaurants[n].food_type);
    			strcpy (restaurants[n].food_type,restaurants[j].food_type);
    			strcpy (restaurants[j].food_type,tfood_type);
    
    			tav_cost=restaurants[n].av_cost;
    			restaurants[n].av_cost=restaurants[j].av_cost;
    			restaurants[j].av_cost=tav_cost;
    		}
    	printf("Please enter the food type=");
    	gets (target);
      for (n=0; n<N_restaurant; n++)
    
      
        printrestaurant (restaurants[n]);
    
    }
    And that's it!

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Try 'struct restaurant_t restaurant'.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >void printrestaurant (restaurant_t restaurant);
    void printrestaurant (struct restaurant_t restaurant);

    Unless restaurant_t is a typedef, you must include the struct keyword. Don't forget to fix the definition of printrestaurant as well.
    My best code is written with the delete key.

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Since no one has mentioned it:

    Why gets() is bad / Buffer Overflows

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Maha! I beat Prelude!
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    This is an advanced C question?
    Do not make direct eye contact with me.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    You can simplify all the swapping in the sort function by using structure assignments

    Code:
    struct restaurant_t temp;
    
    temp = restaurants[n];
    restaurants[n] = restaurants[j];
    restaurants[j] = temp;
    I wonder if your compiler is too old to do that?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    8

    Run time error message

    It compiles! Perfect! However when i run it and try entering the cost it crashes and message displayed is:
    scanf : floating point formats not linked. Abnormal program termination.
    What do i do now to rectify this?

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    1. Change your compiler to something a bit more modern
    www.compilers.net
    has many examples

    2. create the following var in your code
    Code:
    double my_compiler_is_dumb = 1.0;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    When i compile the code with Turbo C 2.01 from Microsoft Corp i get the 2 errors. They occur at
    Wow. That's really really old. Antique (link) even. But Borland seems to think they're the ones that made it.

    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    Registered User
    Join Date
    May 2004
    Posts
    8
    Thanks mate...........already have changed it to Dev-C++ from Bloodhound S/W as it can handle both C and C++.

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >as it can handle both C and C++.
    Just be sure not to compile as C++ when you really wanted C. There are subtle differences between the two language definitions that could easily trip you up.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advanced Piping Question!
    By Paul22000 in forum C Programming
    Replies: 14
    Last Post: 04-17-2009, 09:55 AM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  3. Advanced but yet general
    By Rhodium in forum C Programming
    Replies: 6
    Last Post: 08-09-2003, 12:46 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21