Like Tree1Likes
  • 1 Post By laserlight

missing prototype ?

This is a discussion on missing prototype ? within the C Programming forums, part of the General Programming Boards category; I did put in the function prototype, but it said missing .. Code: #include<stdio.h> int fnDeterminePrice(int); float fnCalc(float , int); ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    29

    missing prototype ?

    I did put in the function prototype, but it said missing ..

    Code:
    #include<stdio.h>
    
    
    int fnDeterminePrice(int);
    float fnCalc(float , int);
    void fnPrintResult(float);
    void fnMenu();
    
    
    int main() 
    {
    	int iCode, iQty;
    	float fPrice, fPay;
    
    
    	fnMenu();
    
    
    	printf("enter item code and quantity:");
    	scanf("%d %d", &iCode,&iQty);
    
    
    	fPrice = fnDeterminePrice( iCode);
    	fPay = fnCalc( fPrice , iQty);
    
    
    	fnPrintResult(fPay);
    
    
    	return 0;
    }
    
    
    void fnMenu()
    {
    	printf("1:Nasi lemak , 2:mee, 3 : sushi ");
    }
    
    
    int fnDeterminePrice( int itemCode)
    {
    	float fPricing;
    	switch (itemCode) 
    	{ 
    		case 1 : fPricing = 1.50; break; 
    		case 2 : fPricing = 2.00; break;
    		case 3 : fPricing - 3.40; break;
    		default : fPricing = 0.00;
    	}
    	return (fPricing);
    }
    
    
    float fnCalc( float fitemPrice , int iQuantity ) 
    {
    	float total;
    	total = fitemPrice * iQuantity ;
    	return ( total);
    }
    
    
    void fnPrintResult( float fPayment )
    {
    	printf("the price is %.3f " , fPayment);
    }
    can someone tell me the mistakes ?
    thank you

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    What's the exact error you're receiving? Copy it and paste it here.

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    29
    Building slideshow3.obj.
    C:\Users\Eric\Documents\Pelles C Projects\C4\slideshow3.c(27): warning #2027: Missing prototype for 'fnMenu'.
    Done.


    this is the error

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    That's certainly there. Something weird with Pelles C, like maybe you didn't save the file after you added the prototype?

    Also, I get this warning:

    Code:
    foo.c:47:21: warning: expression result unused [-Wunused-value]
                    case 3 : fPricing - 3.40; break;

  5. #5
    Registered User
    Join Date
    Dec 2012
    Posts
    29
    ok..so it means that error is some kind of bug ?

    ok..thanks .I have fix that

  6. #6
    Registered User
    Join Date
    Jun 2010
    Location
    Michigan, USA
    Posts
    138
    I would change the prototype and the definition to be:
    Code:
    void fnMenu(void)
    The item in the declaration list:
    Code:
    void fnMenu();
    just defines the return type but not the parameters. This was used in K&R C. I am not sure what the standard says about whether this is a "prototype" or not.

  7. #7
    Registered User
    Join Date
    Dec 2012
    Posts
    29
    putting the void in it clear the error

    thank you !

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    2,690
    just defines the return type but not the parameters. This was used in K&R C. I am not sure what the standard says about whether this is a "prototype" or not.
    Yes both are "prototypes" but one takes no arguments (void), the other can take an unspecified number of arguments. The following is legal in C.

    Code:
    int test();
    
    int main()
    {
    
       test();
       test(1);
       test(1, "HELLO");
    }
    
    int test(int one, char* two)
    {
       return(0);
    }
    Jim

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,390
    Quote Originally Posted by pheininger
    just defines the return type but not the parameters. This was used in K&R C. I am not sure what the standard says about whether this is a "prototype" or not.
    Quote Originally Posted by jimblumberg
    Yes both are "prototypes" but one takes no arguments (void), the other can take an unspecified number of arguments.
    No, the declaration without the void is not a function prototype.
    Quote Originally Posted by C99 Clause 6.7.5.3 Paragraph 14c
    The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied.
    Quote Originally Posted by C99 Clause 6.2.1 Paragraph 2d
    A function prototype is a declaration of a function that declares the types of its parameters.
    jimblumberg likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. First Prototype gone bad...
    By videoboyje in forum C++ Programming
    Replies: 5
    Last Post: 06-12-2011, 10:58 PM
  2. Noticing a pattern of missing prototype warnings
    By tgp1994 in forum C Programming
    Replies: 7
    Last Post: 08-04-2010, 02:08 PM
  3. prototype
    By chico1st in forum C Programming
    Replies: 3
    Last Post: 05-26-2008, 06:48 AM
  4. Replies: 8
    Last Post: 10-07-2004, 08:30 AM
  5. Prototype
    By Kelvin in forum C Programming
    Replies: 2
    Last Post: 07-12-2002, 07:06 AM

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