Breaking the string

This is a discussion on Breaking the string within the C++ Programming forums, part of the General Programming Boards category; I have a string variable declared char str[50]; I have a starting postion and number of characters. How can I ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    3

    Breaking the string

    I have a string variable declared

    char str[50];

    I have a starting postion and number of characters. How can I get the substring?

    Thanks,
    Balaji

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    char String[50] = "Halleluja!";
    char SubString[50];
    
    for(int i = StartPosition; i < (StartPosition + NrOfChars); i++)
    {
       SubString[i - StartPosition] = String[i];
    }
    SubString[StartPosition + NrOfChars] = '\0';
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please check my C++
    By csonx_p in forum C++ Programming
    Replies: 263
    Last Post: 07-24-2008, 09:20 AM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  3. String Class Operations
    By Aidman in forum C++ Programming
    Replies: 10
    Last Post: 04-06-2003, 02:29 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM
  5. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 11:40 AM

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