> I am playing with some C code, but am really a beginner with it.
> I want to write a piece of code that will look at a string with
> repeating information:
> (originated by foo) (originated by foo2) etc...
> and truncate the string before the second "originated", where
> the word originated always begins each section. I can't quite
> get it right. Can anyone help?
You should move this to a C group, as this is not a UNIX question.
I suppose what I would do is:
1 - Figure out how the first chunk of information ends. Is it the
first ). Is it ) followed by <space>. Think about the strange cases,
(originated by foo)) (originated by foo2)
(originated by foo) ) (originated by foo2)
(originated by originated)) (originated by foo2)
and so on.
2 - Use something like strstr() to find the end of the first chunk.
3 - Move the pointer to the end of the first chunk.
4 - Write a NUL terminator to truncate the string if you are allowed
to modify the string. Otherwise subtract the pointers, malloc()
memory, memcpy(), and then terminate the string.