Thread: how to copy strings from mid way through

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    14

    how to copy strings from mid way through

    hi all
    i have used a combination of strchr and strncpy to get the string name so i could create the file. now i need to copy the contents of the file so i can put it into the file i had just created. because this starts from mideway im just finding it a little tricky. everything is saved in a format in 1 file now i am trying to extract everything from this file so i could recreate the files they once were.

    if there was a way to carry on reading the file after the loop or if there is a way to just read the file midway through the with only the point indicators starting start and finish

    kind regards

    im guessing the answer lies in string.h so thats what im going to research

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    A FILE keeps a "read pointer", which is roughly "this is where the last thing that was read stopped, and therefore this is where the next thing that is read will start". If you go through the whole file and then go back, you can do a tell/seek to keep track of a particular place.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    14
    im a complete stranger to the tell and seek functions
    ive just done some research on both of them and didnt understand them well enough

    could you shine some light please

    i had though the system would keep a pointer at where it had finished but for some odd reason it hadnt and it started from the start of the string

  4. #4
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Let's say you are only interested in file contents that's only between "start" and "finish" words., how would you know which part of file has the word start?
    You don't. you have to search that word (by reading the file).
    If you post the sample input file and explain clearly what you are trying to do, we could help in more details..

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by stephen101 View Post
    i had though the system would keep a pointer at where it had finished but for some odd reason it hadnt and it started from the start of the string
    So you need to keep your words straight. The title of the thread is reading from the middle of the string. The first post was reading from the middle of a file. Now we're back to reading from the middle of a string again. You need to decide what you have, first, and then we can discuss what to do from there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting Array of Strings
    By nair in forum C Programming
    Replies: 6
    Last Post: 10-09-2010, 11:10 AM
  2. swapping strings (which are stored in an array)
    By nair in forum C Programming
    Replies: 2
    Last Post: 10-04-2010, 01:27 PM
  3. need to find duplicate strings in file`
    By e.vikaas in forum C Programming
    Replies: 6
    Last Post: 08-14-2010, 10:45 AM
  4. How can i make a unique copy of strings?
    By what3v3r in forum C++ Programming
    Replies: 9
    Last Post: 01-12-2006, 09:11 PM
  5. Using strings with the copy constructor
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 08-29-2001, 03:04 PM