string to integer

This is a discussion on string to integer within the C Programming forums, part of the General Programming Boards category; I have a string in form of a date eg . "10/23/2010" i'd like to convert it to integer such ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    6

    string to integer

    I have a string in form of a date eg . "10/23/2010"
    i'd like to convert it to integer such that
    int day = 23
    int month = 10
    year = 2010

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Code:
    char date[] = "10/5/2010";
    
    sscanf( date, "%d/%d/%d", &d, &m, &y );
    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    3

    You can use strtok with delimeter as "/"

    Note: strtok modifies the orginal string

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polymorphism and generic lists
    By Shibby3 in forum C# Programming
    Replies: 9
    Last Post: 07-26-2010, 05:27 AM
  2. help assignment due tomorrow
    By wildiv in forum C Programming
    Replies: 6
    Last Post: 01-27-2010, 07:38 PM
  3. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  4. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 10:32 AM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-26-2003, 11:03 PM

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