Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing strings 3

Status
Not open for further replies.

keano6

Programmer
Feb 25, 2003
4
0
0
CN
Hi,

I'm new to c++, and am trying to parse a string and find the number of lines...

I am having problems finding all the carriage returns with the following code:

char* tmp;

//skip to the end of the line
while (*tmp != '\n')
tmp++;

Is there a better way of finding this character?

Thanks.
 
>I'm actually shocked to see that question

you are shocked,i see...
i mean why am i geting so much attention for one single error??? Should we start World War III because of it? Anyway it wasn't really an error,it was intentional.If the first character is not a carriage return,the original code will cause no problem at all.And also that wasn't a complete program,just a code sample which means that you could have to do some reajustment before actualy using it.

I just dont get it...
you've said it yourself: "it's a trivial example".
so why geting so religious about it?

>Since two persons has noted it's a bit obfuscated that should be proof enough.

Now,i'm shocked...
I have corrected the problem with the original post,THAT SHOULD BE ENOUGH. By the way,i think that i could find even more people to defend my case since this is a very trivial example.

The way i see it,it should have been something like you've made a little mistake in your original code,then i make the correction and now it should be over.

And talking about mistakes,everyone makes them:
>Is it obvious that the *tmp compared to 0 and the *tmp compared to '\n' aren't the same *tmp due to the *(tmp++)?

code sample: while( *(tmp++) != 0 ) if( *tmp == '\n' ) count++;

would you like to clarify your question?


 
>And talking about mistakes,everyone makes them

Of course. We all do that. And since we know we all do that we should realize the importance of using tools (such as code design) so we at least make less mistakes.

>you've said it yourself: "it's a trivial example".
>so why geting so religious about it?

More frustrated than religous as I don't seem able to explain that it isn't the actual code itself Im discussing, but the design descicions behind it. The code in question was just used for illustrating the point I'm trying to make.

>would you like to clarify your question?

It was a rethorical question with the answer "No".

Anyway, I've given up. It all bottles down to
Code:
"Any fool can write code that a computer can understand.
Good programmers write code that humans can understand."
from R. Fowler, Refactoring: Improving the Design of Existing Code (which I recommend you'd read if you'd actually be interested in what I try to say, though I doubt you are)

I won't spam this thread any more, drop me a mail if you want to discuss it further. perfnurt@hotmail.com



/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
>Any fool can write code that a computer can understand.
(Lets make this very clear,i'm far from being a fool.)

>I won't spam this thread any more, drop me a mail if you want to discuss it further.

Thanks,that will be all,i'm giving up on this discussion.
Anyway,i understand your point for the code readability,by the way i dont have any reputation for making unreadable code(the current code sample was just a trivial example.)


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top