Thread: Expected expression before char

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    158

    Expected expression before char

    Code:
     #include <stdio.h>
        void instructions_white_single_manual();
        void instructions_white_single_bake();
        double instructions_white_double_manual();
        double instructions_white_double_bake();
       
        void instructions_sweet_single_manual();
        void instructions_sweet_single_bake();
       double instructions_sweet_double_manual();
       double instructions_sweet_double_bake();
        Line 12double calc_baking_time(char bread_type, char loaf, char manual);
       int main()
       {
               char bread_type;
               char loaf;
               char manual;
               printf("Are you making white or sweet bread (w or s)? ");
               scanf(" %c",&bread_type);
      
               printf("Is this a single or double loaf (s or d)? ");
               scanf(" %c",&loaf);
      
               printf("Are you going to bake manually (y or n)? ");
               scanf(" %c",&manual);
      
               if ((bread_type=='w'||bread_type=='W')&&(loaf=='s'||loaf=='S')&&(manual=='y'||loaf=    ='Y'))
               {
                        instructions_white_single_manual();
               }//if
               else//else if
                 if ((bread_type=='w'||bread_type=='W')&&(loaf=='s'||loaf=='S')&&(manual=='n'||loa    f=='N'))
               {
                        instructions_white_single_bake();
               }
               else//else if
                 if ((bread_type=='w'||bread_type=='W')&&(loaf=='d'||loaf=='D')&&(manual=='y'||loa    f=='Y'))
               {
                        instructions_white_double_manual();
               }
               else//else if
               if ((bread_type=='w'||bread_type=='W')&&(loaf=='d'||loaf=='D')&&(manual=='n'||loaf=    ='N'))
               {
                        instructions_white_double_bake();
               }
               else//else if
               if ((bread_type=='s'||bread_type=='S')&&(loaf=='s'||loaf=='S')&&(manual=='y'||loaf=    ='Y'))
               {
                        instructions_sweet_single_manual();
               }
               else// else if
               if ((bread_type=='s'||bread_type=='S')&&(loaf=='s'||loaf=='S')&&(manual=='n'||loaf=    ='N'))
               {
                        instructions_sweet_single_bake();
               }
                  else// else if
               if ((bread_type=='s'||bread_type=='S')&&(loaf=='d'||loaf=='D')&&(manual=='y'||loaf=    ='Y'))
               {
                        instructions_sweet_double_manual();
               }
               else// else if
               if ((bread_type=='s'||bread_type=='S')&&(loaf=='d'||loaf=='D')&&(manual=='n'||loaf=    ='N'))
               {
                        instructions_sweet_double_bake();
               }
                 return 0;
       }
               void instructions_white_single_manual()
       {
               printf("Primary kneading: 15 mins\n");
      
               printf("Primary rising: 60 mins\n");
      
               printf("Secondary kneading: 18 mins\n");
      
               printf("Secondary rising: 20 mins\n");
      
               printf("Loaf shaping: 2 seconds\n");
      
               printf("You should remove the dough for manual baking.\n");
      
    Line 82 calc_baking_time(char bread_type, char loaf, char manual);
       }// instructions_white_single_manual


    I'm trying to call the function calc_baking_time, but i don't see what else is missing?
    bread.c: In function 'instructions_white_single_manual':
    bread.c:82:19: error: expected expression before 'char'
    bread.c:82:19: error: too few arguments to function 'calc_baking_time'
    bread.c:12:8: note: declared here


    i do apoligize for the lines not appearing correctly
    Last edited by tmac619619; 10-23-2012 at 03:01 PM.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Try to keep this to a single thread.

    And try to provide a complete program (i.e. with a proper "main()" function) so we can better help you with the problem.

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    357
    There are 4 things you can do with a function:
    a) define them
    b) provide a prototype for them
    c) provide a declaration (kinda like a prototype) for them
    d) call them

    In your code, in line 81, it looks like you want to call a function, but you provide a prototype instead.

    a) definition
    Code:
    int foo(int a) { return a + 42; }
    b) prototype
    Code:
    int foo(int a);
    c) declaration
    Code:
    int foo();
    d) call
    Code:
    foo(-2);

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    158
    Quote Originally Posted by qny View Post
    There are 4 things you can do with a function:
    a) define them
    b) provide a prototype for them
    c) provide a declaration (kinda like a prototype) for them
    d) call them

    In your code, in line 81, it looks like you want to call a function, but you provide a prototype instead.

    a) definition
    Code:
    int foo(int a) { return a + 42; }
    b) prototype
    Code:
    int foo(int a);
    c) declaration
    Code:
    int foo();
    d) call
    Code:
    foo(-2);
    I understand.
    In this particular adjustment
    Code:
     double calc_baking_time(char bread_type, char loaf, char manual);      
    
    int main ()
    {
    }
    void instructions_white_single_manual()
       {
               printf("Primary kneading: 15 mins\n");
    
               printf("Primary rising: 60 mins\n");
    
               printf("Secondary kneading: 18 mins\n");
    
               printf("Secondary rising: 20 mins\n");
    
               printf("Loaf shaping: 2 seconds\n");
    
               printf("You should remove the dough for manual baking.\n");
    
    Line 82 calc_baking_time();
    

    I attempt to call the function, but get the error too few arguments.
    Now if i go to the prototype and change it to
    Code:
    calc_bake_time();
    .
    I would get an undefined variable error later on in my program, since i didn't pass any variables to the function

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by tmac619619 View Post
    Now if i go to the prototype and change it to
    The question is (which you can only answer yourself): what should this function do? Does it need three arguments or none?
    Since you are the programmer you have to know what you want.
    If you need three arguments then you have to call it with three arguments.
    If you don't need any arguments then you have to change the prototype and call it without any arguments.

    Bye, Andreas

  6. #6
    Registered User
    Join Date
    Oct 2012
    Posts
    158
    My function needs arguments
    Code:
    double calc_bake_time(char bread_type, char loaf, char manual);
    But when i try to call the function
    Code:
         void instructions_white_single_manual()
       {
               printf("Primary kneading: 15 mins\n");
    
               printf("Primary rising: 60 mins\n");
    
               printf("Secondary kneading: 18 mins\n");
    
               printf("Secondary rising: 20 mins\n");
    
               printf("Loaf shaping: 2 seconds\n");
    
               printf("You should remove the dough for manual baking.\n");
    
    
     calc_baking_time();
    


    From the void function, i keep getting too few arguments/ expected an expression before 'char' error.

    I am calling the function correctly, right?
    Code:
    calc_baking_time();

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    This is how you call the function from another function:

    Code:
    void testFunction(void)
    {
        char bread = 'b';
        char loaf = 'f';
        char manual = 'm';
    
        // code
    
        calc_baking_time(bread,loaf,manual);
    }
    Note that the variable names you feed to the function during the function call do not have to be the same as the variable names in the function declaration/definition.

    Code:
    void testFunction(void)
    {
        char one = 'b';
        char two = 'f';
        char three = 'm';
    
        // code
    
        calc_baking_time(one,two,three);
    }

  8. #8
    Registered User
    Join Date
    Oct 2012
    Posts
    158
    Quote Originally Posted by Matticus View Post
    This is how you call the function from another function:

    Code:
    void testFunction(void)
    {
        char bread = 'b';
        char loaf = 'f';
        char manual = 'm';
    
        // code
    
        calc_baking_time(bread,loaf,manual);
    }
    Note that the variable names you feed to the function during the function call do not have to be the same as the variable names in the function declaration/definition.

    Code:
    void testFunction(void)
    {
        char one = 'b';
        char two = 'f';
        char three = 'm';
    
        // code
    
        calc_baking_time(one,two,three);
    }
    I'm getting very close to being able to run this!
    one last thing. If i cann't use global variables. Must i define char bread_type;
    char loaf;
    and char manual;
    in each function?

    Code:
    void instructions_white_single_manual(char bread_type, char loaf, char manual)
    {
           printf("xoxo");
       calc_bake_time(bread_type, loaf, manual);
    }
    correct format?
    Last edited by tmac619619; 10-23-2012 at 03:51 PM.

  9. #9
    Registered User
    Join Date
    Oct 2012
    Posts
    158
    WOOW MYPROGRAM WORKED

    250+ freaking lines.

    Shout out to Matticus, Andreas, and QNY!!!!!!!!!!!!!!!!1

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. expected expression before ')' token
    By m_programmer in forum C Programming
    Replies: 6
    Last Post: 09-14-2012, 08:02 AM
  2. expected constant expression?
    By GroogFish in forum C Programming
    Replies: 3
    Last Post: 05-08-2012, 12:17 AM
  3. expected primary-expression before ']'
    By ooopa in forum C++ Programming
    Replies: 4
    Last Post: 11-14-2011, 09:35 AM
  4. error: expected an expression
    By cdmstr in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2011, 02:00 PM
  5. expected primary expression
    By mju4t in forum C Programming
    Replies: 2
    Last Post: 03-27-2007, 06:59 PM