more casting problems none solutions have worked

This is a discussion on more casting problems none solutions have worked within the C Programming forums, part of the General Programming Boards category; Now sorry if im double posting this code but the replies wernt clear enough. Im getting casting errors could someone ...

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

    more casting problems none solutions have worked

    Now sorry if im double posting this code but the replies wernt clear enough.
    Im getting casting errors could someone help me fix them it says:
    assignment makes integer without cast .... but i have made an atoi cast. Then it says passing arg 1 atoi makes integer without cast... could somone fix it for me...

    im only trying to tokenize the system date then put it into seperate int variables..


    Code:
    /****************************************************************************
    * This function prompts the user for a 10-character date of birth in
    * dd/mm/yyyy format. The system date is extracted with the assistance of the
    * time.h header file. This function reports how many days old the user is.
    * Dates of birth after the current date are rejected.
    ****************************************************************************/
    void ageCalculator()
    {
     char buff[BUFSIZ];
     struct tm t;
     time_t now;
     int m,d,y;
     char input [MAXDATE]; /* buffer size is 12 */
     int valid = 0;
     
     char*  dayr, monthr, yearr;
     int dR, mR, yR;
     /* declaration of variables */
    
     time(&now); 
     /* put now into time */
    
     t = *localtime(&now); 
     /* get the current date */
    
     strftime(buff, sizeof(buff), "%d//%m//%y", &t); 
     /* format the date*/
      
    
     /* --- printing the date ---- */
      printf("The current date is %s\n",buff);
    
      printf("\nPlease Enter your age in dd/mm/yyyy format:");
    
       fgets(input, MAXDATE, stdin);
    
      do
      {
    
       if ( fgets ( input, sizeof input, stdin ) != NULL ) 
       {
         valid = 0;
           
       }     
    
        if ( sscanf ( input, "%d/%d/%d", &m, &d, &y ) == 3 )
         {
          if ( is_valid ( m, d, y ) )
          {
            printf ( "\n\n%d/%d/%d is a valid date\n", m, d, y );
            valid = 1;
          }
        }
          else
          {
            printf ("\nInvalid date please enter in dd/mm/yyyy format:");
            valid = 0;
          }
       }
       while(!valid);    
       
     /*  day = strtok(input, "/");
       if (day) printf("%s\n", day);
    
        month = strtok(NULL, "/");
        if (month)   printf("%s\n", month);
    
       year = strtok(NULL, "/");
       if (year) printf("%s\n", year);   
       loopyear();*/
    
       dayr = strtok(buff, "/");
       dR = atoi(dayr);
       printf("%d\n", dR);
    
       monthr = strtok(NULL, "/");
       mR = atoi(monthr);
       printf("%d\n", mR);
    
       yearr = strtok(NULL, "/");
       yR = atoi(yearr);
    
     }
    
    
    int is_valid ( int m, int d, int y )
    {
      static const int  mday[] =
      {
        0,31,28,31,30,31,30,31,31,30,31,30,31
      };
    
      if ( m <= 0 || m > 12 )
        return 0;
      else if ( d <= 0 || d > mday[m] )
        return 0;
      else if ( y < 1900 || y > 3000 ) /* Arbitrary choices */
        return 0;
    
      return 1;
    }
    
    int loopyear()
    {
     int days = 0;
     int leapdays;
     int nonleapdays;
     int year;
    
     leapdays = year % 4;
     nonleapdays = year % 100;
    
     days = leapdays - nonleapdays;
     printf("\n%d number of days",days);
     return days;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,336
    DUDE!!!!
    Like I said in your other post here http://forums.devshed.com/t284906/s.html

    You've already converted the values once (check the values in y,m,d)
    There's no point faffing about with strtok and atoi to do the whole thing again.

    Sheesh!
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Have a few minor problems trying to finish this program
    By kisiellll in forum C Programming
    Replies: 4
    Last Post: 02-22-2009, 06:00 PM
  2. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  3. casting problems warnings segmentation fault.
    By BSmith4740 in forum C Programming
    Replies: 13
    Last Post: 07-03-2008, 12:13 PM
  4. Having problems with arrays
    By pokiepo in forum C Programming
    Replies: 4
    Last Post: 06-18-2008, 01:27 AM
  5. Problems with the eight queens problem
    By Wicket in forum C++ Programming
    Replies: 1
    Last Post: 06-12-2008, 09:29 AM

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