Thread: Calling certain characters from a string.

  1. #1
    Registered User
    Join Date
    Aug 2006

    Calling certain characters from a string.

    I'm not sure how to explain what I want to try and do but basically if I have a string of numbers ie: 123456789 I want to be able to call out all the numbers in the odd positions ie 2,4,6,8.

    Any tips or pushes in the right direction?

    Hope that makes sense. Thanks.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    Try this for loop:
     int i;
      for(i = 1;i < length_of_string;i += 2)
        // code to print number goes here
    If you understand what you're doing, you're not learning anything.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    for ( i = 1 ; i < len ; i += 2 )
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  4. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM