Hi I have a small problem!! Need Quick Help

This is a discussion on Hi I have a small problem!! Need Quick Help within the C++ Programming forums, part of the General Programming Boards category; Hi UAll I want to token out the int from the string "10:20:30", so in these case i have a ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    68

    Lightbulb Hi I have a small problem!! Need Quick Help

    Hi UAll

    I want to token out the int from the string "10:20:30", so in these case i have a delimiter as ':'.

    Why do i want to do these, because i have to find out the total second in time stamp.

    Please Help me
    I tried many way but it does not work, may be i am not thinking right.
    Thanks

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Post some code and we'll be happy to help.

    You can copy the string upto the ':' delimiter and then use atoi to convert to your integers(hour, minute, seconds).

    Then you can do your conversion after you grabbed all the values.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    68
    Here is you go this is what i am trying. I don't know what i am doing wrong

    Please look at the code and help me
    Thanks
    ---------------------------------------------------------------------------------
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int strchrall (const char *z,int b)
    {
      int rValue = 0;
      int Signal = 1;
      b = (char) b;
    
      do{
        if(*z == b)
        {
          rValue = rValue + 1;
        }
        if (*z++ == '\0')
        {
            Signal = 0;
        }
      } while(Signal);
      return rValue;
    }
    
    
    int main ()
    {
      int all = 0;
      int Mintues = 0;
      int Second = 0;
      int Hours = 0;
    
      // these will tell me how many times
     // the delimeter occures in a string
      all =  strchrall ("0:00:00",':');
    
     // the string can be from the following
     // only second 60
     // minutes and seconds 01:60
     // hours, minutes and seconds 10:20:30
     // Having problem figuring out these logic
     // All i want out of this is Total Second from time format....
     for(int nIndex = 0, nIndex <= all;nIndex++)
    {
        if(all == 0)
       {
           Second = atoi(strtok(0:00:00,":"));
       }
       else if (all == 1)
       {
           Mintues = atoi(strtok(0:00:00,":"));
           char *temp;
           while(temp != NULL )
           {
                          
           }
       }
    }
    
    
      return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual C++ small problem
    By gadu in forum C++ Programming
    Replies: 0
    Last Post: 03-10-2009, 11:45 PM
  2. Small problem with this array...
    By Merholtz in forum C Programming
    Replies: 7
    Last Post: 11-03-2008, 04:16 PM
  3. Help with a small problem (beginner)
    By piffo in forum C Programming
    Replies: 13
    Last Post: 09-29-2008, 05:37 PM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. Need Big Solution For Small Problem
    By GrNxxDaY in forum C++ Programming
    Replies: 8
    Last Post: 08-01-2002, 04:23 AM

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