Campbell Ritchie wrote:How do you know that the word CHAPTER will always be in the same *char (=char[])? Are you reading line by line or 256 chars at a time? Do you expect CHAPTER ONE to appear more than once in the book? Is there a built‑in function to find substrings embedded in *char/char[]s?
Campbell Ritchie wrote:Presumably you find the first occurrence of the C in CHAPTER, use strcpy for the remainder of the String, and put a \0 in place of the C. A little wasteful of memory, maybe, but it will only be a few kB per book.
If CHAPTER XXX is always on a line by itself, all you need to do is to find whether CHAPTER is a “prefix” of that particular *char/char[].
If you cannot find a built‑in prefix procedure, you can write your own. One suggestion: copy the first seven letters into a new *char/char[] and see whether that is equal to CHAPTER with strcmp.
Campbell Ritchie wrote:If you are repeatedly reading lines it is quite easy to use strcmp to find whether a line is equal to CHAPTER ONE, and you can use the title as the name of the next file.Remember strcmp returns the difference between two *chars, so it returns 0 for equality. That depends on the lines being exactly equal, including case and any spaces. Beware of trailing spaces, because CHAPTER ONE and CHAPTER ONE are different.
I seem to have merged the two discussions in the wrong order. Sorry.
You can use c, cpp or c++ in the code tags, it would appear. More details in the ranch guide (scroll to the bottom).