Thread: passing reference to fucntion

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    passing reference to fucntion

    Hey guys i keep getting a warning in ansi c sayin implicit function declaration where i see nothing wrong with it. Its complaing about the MainMenu() function. Could someone give me a hand here?



    Code:
    #include "ts.h"
    #include "ts_utility.h"
    #include "ts_options.h"
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    int commandLineArguments(int, char**);
    int mainMenu(int*);
    
    int main(int argc, char** argv)
    {
       TennisStoreType ts;
       commandLineArguments(argc, argv);
       MainMenu(&main);
    
       return EXIT_SUCCESS;
    }
    
    int commandLineArguments(int argc, char **argv) 
    {   
        /* makes a local copy of argc and **argv */
    
     
       FILE *customer, *stock, *logfile; 
       
        /* declares a pointer to each file*/
    
        /* test if 4 arguments exist including the exucutable*/
    
       if(argc !=4) 
       {
         printf("please enter 3 cmd arguments!\n");
         return 1;  
         /* stop pocessing*/
       }
    
        /* attempt to open and read arg 1*/
    
       customer = fopen(argv[1], "r");
    
        /* check if custome.csv exists*/
    
       if(customer ==NULL)
       {
         printf("cannot open %s for reading\n", argv[1]);
         return 1;  
         /* can't go on*/
       }
    
         /* try to open stock.csv and read it*/
    
       stock = fopen(argv[2], "r");
      
         /* if stock.csv does not exist error*/
       
       if(stock == NULL)
       {
         printf("cannot open %s for reading\n",argv[2]);
         return 1;  
    
         /* stop processing*/
       }
    
         /* open logfile for reading */  
     
       logfile = fopen(argv[3], "r");
    
         /* check if logfile exists*/
    
       if(logfile == NULL)
       {
         printf("cannot open %s for reading\n", argv[3]);
         return 1;  
     
         /* stop processing*/
       }
       
         /* close all files */
    
       fclose(customer);
       fclose(stock);
       fclose(logfile);
    
       return 0;
    
        
    }
    
    int MainMenu(int *c)
    {
    
      int choice = 0;
      /* declare variables*/
      
      
      do
       {
    
         printf("\nMain Menu:");
         printf("1) Add Customer\n");
         printf("2) Add Stock\n");
         printf("3) Delete Record\n");
         printf("4) Display Customer\n");
         printf("5) Display stock\n");
         printf("6) Make Sale\n");
         printf("7) Sales Log\n");
         printf("8) Save and Exit\n");
         printf("9) Abort\n");
    
         fscanf(stdin, "%d",&choice);
    
         switch(choice)
         {
           case 1:
           printf("Add stock");
           break;
    
         }
    
      }
      while(choice !=9);
      
    
      /* switch case */
    
      /*  do while
    
      /* while !=10 */  
    
      return 0;
    }

  2. #2
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    You have the declaration:

    int mainMenu(int*);

    But the function definition:

    int MainMenu(int *c)

    Notice the difference in the case of the first letter.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    The porototype it is
    Code:
    int mainMenu(int*);
    The actulal function you are calling is
    Code:
    MainMenu(&main);
    Kurt
    edit: Too late again.

  4. #4
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    haha, i keep beating you to the answers, ZuK :P

    Don't worry, leaving work now, so won't be posting for a while.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > MainMenu(&main);
    What on earth are you hoping to achieve with this (assuming you even get the prototype right)?
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM