char[] -> int conversion

This is a discussion on char[] -> int conversion within the C++ Programming forums, part of the General Programming Boards category; hello everybody say i have a variable: char date[20] where date is equal to: 12/01/99 is there anyway i could ...

  1. #1
    Makimura
    Guest

    char[] -> int conversion

    hello everybody

    say i have a variable:

    char date[20]

    where date is equal to:

    12/01/99

    is there anyway i could read it where i could make 12, 01, and 99 separate integer variables?


    Makimura

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    Code:
    #include <cstdio>
    
    int main()
    {
        char date[] = "12/01/99";
        int day, month, year;
    
        sscanf(date, "%d/%d/%d", &day, &month, &year);
        printf("Day: %d\nMonth: %d\nYear: %d", day, month, year);
    
        return 0;
    }
    - lmov

  3. #3
    Makimura
    Guest
    thx

    by any chance is there a wat to do it by iostream ?

    Makimura

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 06:45 AM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM

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