Printing a substring based on char start and stop number

This is a discussion on Printing a substring based on char start and stop number within the C Programming forums, part of the General Programming Boards category; Say I have a string (an array of characters) that is 1000 characters long. I want to print a substring ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    30

    Question Printing a substring based on char start and stop number

    Say I have a string (an array of characters) that is 1000 characters long. I want to print a substring made up of the characters 50 to 100. How do I do that?

    -I have looked at the string library and don't recognize a solution.
    -Should I create a new smaller array somehow --- perhaps a loop?

    yep, I'm a newb.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You need to look at the string library again, with the caveat that the words they use may not exactly match the words you are using. For instance, there's strncpy.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,657
    If you just want to print it, simply start at index 49 and print up to index 99. If you want to make a copy use a similar approach, but instead of printing, copy the data to a buffer somewhere (don't forget to null terminate the string, though).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unkown Hang
    By Bladactania in forum C Programming
    Replies: 31
    Last Post: 04-22-2009, 09:33 AM
  2. C programing doubt
    By sivasankari in forum C Programming
    Replies: 2
    Last Post: 04-29-2008, 09:19 AM
  3. why cant i start the process i stop using SIGCONT
    By cruxxe in forum C Programming
    Replies: 0
    Last Post: 06-06-2002, 09:06 AM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

Tags for this Thread


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