function calling

Discussion in 'C' started by musicmancanora4, Mar 12, 2006.

  1. musicmancanora4

    musicmancanora4 New Member

    Joined:
    Mar 9, 2006
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    0
    I just want to be able to successfully call the validate Month function inside the getMonth function.. it works when i call getUserInput() but i get type cast errors if i try it with this function. Any idea as to how i can write it up? thnxs




    Code:
    unsigned getMonth()
    {
       
       /*** declare variables*/
      
      unsigned  i;
      int  valid = 0;
      char *prompt = "Please enter a month between 0 - 12\n";
      char *month;
      
      
      
      do
      {
      
      month = getUserInput(prompt);
      /* in here i want to call the validateMonth() fucntion*/
    
      }
      while(!valid);
      /*printf("hello %s",month);*/
      /*printf("Please enter a month between 0 - 12\n");*/
      
     
       
       return EXIT_SUCCESS;
    
    }
    
    Code:
    unsigned validateMonth(unsigned month)
    {
         unsigned m;
         while(month<0 || month>12)
         {
            
            printf("Month error 0 or less or equal to 12 please\n");
            
         }
    
         return m;
    }
    
    
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Because the prompt is a character pointer and the function argument for validateMonth is unsigned. i.e. integer.
     
  3. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    38
    Trophy Points:
    28
    Isnt the error evident enough.
     
  4. musicmancanora4

    musicmancanora4 New Member

    Joined:
    Mar 9, 2006
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    0
    the code i have posted is error free. But what im trying to say is that when i try to write the function call for it i get a type cast error for some reason.

    so with the above code how can i call the validateMonth() function inside the getUserInput() function
     
  5. musicmancanora4

    musicmancanora4 New Member

    Joined:
    Mar 9, 2006
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    0
    Its kewl guys i did it yey! thnxs
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Good that its done. Probably you are calling with the different variable type.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice