C string handling question

C string handling question

Post by Doug Amdu » Thu, 07 Oct 1999 04:00:00



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?

Thanks,
Doug

 
 
 

C string handling question

Post by kgol » Thu, 07 Oct 1999 04:00:00



> 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.
But ...

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,
like:

(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.
--


 
 
 

C string handling question

Post by Harald Kirs » Thu, 07 Oct 1999 04:00:00



> 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?

Do you want to find the shortest or the longest repeating string. How
about overlapping sections?

Sounds like a homework question !-)

Harald Kirsch
--
P.S.: Never ever mail me copies of your posts.
---------------------+---------------------------------------------


     A no-smoking area in a restaurant is like a
     no-pee area in a swimming pool.

 
 
 

1. String handling in sh


Change your awk command to look something like this:
    awk '$1 ~ /dsk50|dsk53|dsk29/{print $1}'

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    Cal Dunigan                       My opinions *ARE* the company's

    Consulting, Modeling, Training
//////////////////////////////////////////////////////////////////////

2. Linux Manuals

3. in 'getopt()', how to handle multiple options in the 'optarg' string?

4. ed0 device timeout

5. sparse tool handling of escaped characters in strings

6. What Have I Done?

7. DBCS/MBCS aware string handling functions

8. help: toshiba laptop and X

9. Q: Can dip handle complex strings ?

10. Q: ksh - how to handle strings with spaces

11. String handling on VAC compiler (version 5) on AIX

12. String handling

13. QUESTION: telnet screen handling question