Thread: How to substring ?

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    1

    Question How to substring ?

    Hi All,

    Does anyone know, how to substring a set of characters
    given the start and end positions ?

    I am trying to cut a long string into chunks of 250
    characters and store them in an array.

    Thanks in advance.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Code:
    char buff[100][251];
    for ( i = 0, j = 0 ; i < n ; i += 250, j++ ) {
      strncpy( buff[j], &line[i], 250 );
      buff[j][250] = '\0';
    }
    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. split string and remove substring
    By nyc_680 in forum C Programming
    Replies: 3
    Last Post: 03-02-2009, 04:45 AM
  2. I need help with creating a substring program
    By CProgramingBegg in forum C Programming
    Replies: 9
    Last Post: 02-06-2009, 09:50 AM
  3. longest common substring problem
    By Enchanter88 in forum C++ Programming
    Replies: 4
    Last Post: 09-29-2007, 11:02 AM
  4. Replies: 11
    Last Post: 12-11-2005, 11:50 PM
  5. Getting a substring help plz
    By joshua in forum C Programming
    Replies: 3
    Last Post: 11-01-2005, 06:11 PM