Thread: how do i split a string into two?

  1. #1
    Registered User
    Join Date
    Nov 2016
    Posts
    18

    how do i split a string into two?

    i need to know how can i split a string of characters into two.
    i have one str[8] array and want two str1[4] and str2[4] arrays with str1 having the first half of str and str2 the rest.
    how can i accomplish this?

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    You can use strncpy library function.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    But don't forget that your arrays must have room for the end of string characters. So with a string of size 8 at least one of the "split" strings must have a size of at least 5. Since a string of size 8 can have at most 7 characters, you would end up with string lengths of 3 and 4, which would require array sizes of 4 and 5.

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Split a string(C)
    By oror84 in forum C Programming
    Replies: 4
    Last Post: 04-11-2011, 11:36 PM
  2. Split String
    By puneetlakhina in forum C Programming
    Replies: 1
    Last Post: 10-06-2008, 02:12 AM
  3. Split a string
    By Tommo in forum C Programming
    Replies: 5
    Last Post: 09-01-2007, 04:53 PM
  4. split string
    By gtr_s15 in forum C++ Programming
    Replies: 2
    Last Post: 12-06-2005, 07:20 AM
  5. how to split a string into two?
    By Jasonymk in forum C++ Programming
    Replies: 5
    Last Post: 01-06-2003, 04:48 AM

Tags for this Thread