Calling certain characters from a string.

This is a discussion on Calling certain characters from a string. within the C Programming forums, part of the General Programming Boards category; I'm not sure how to explain what I want to try and do but basically if I have a string ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    127

    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
    Location
    Oregon, USA
    Posts
    3,164
    Try this for loop:
    Code:
    {
     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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    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.
    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. 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, 11:47 AM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 09:33 PM

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