Problem in sorting by name

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Problem in sorting by name

 
0
  #21
Mar 12th, 2007
>You tell that to my colleague who happen to see me swiftly write the code and who checked it.
I don't care how fast you wrote it. I'd rather have good code that someone took time to check, rather than to read quickly-written code that sucks ass.

>As I specified earlier, as you seemed to have ignored, it did compile sucessfully.
I don't know HOW those errors that I stated previously would compile on anything. And if it really did, the compiler deserves to be thrown out the window, because compiler errors are supposed to alert you to mistakes in your code (at least the ones the compiler can see).

>You should be more considerate when make such absolute claims.
Those errors were pretty absolute to me, and I'm sure you cannot deny the mistakes I already pointed out.
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,620
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Problem in sorting by name

 
0
  #22
Mar 12th, 2007
> Well if he is learning then he is a beginner. So what is your point?
So we have to make sure they doesn't pick up wrong programming practices.

All this time you seem to be ignoring, my and Joe's constructive criticism. This is not the way things are done. A working code is not the same as a concise, clear and helpful code. You have to understand that the code which you post in the code snippets section is used and referred by thousands of beginners everyday. A high standard has to be maintained.

Picking at people who have been here for a long time is no solution to the problem. Try to improve yourself.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 171
Reputation: Lazaro Claiborn is an unknown quantity at this point 
Solved Threads: 13
Lazaro Claiborn's Avatar
Lazaro Claiborn Lazaro Claiborn is offline Offline
Junior Poster

Re: Problem in sorting by name

 
0
  #23
Mar 12th, 2007
Originally Posted by ~s.o.s~ View Post
Lazaro, make sure your code is up to the specified standards like Joey said. I see a lot of beginner style programming which may confuse other people trying to learn the language.
I'd really appreciate a link to a standard specification either for C (?) or for Daniweb, seriously.

Originally Posted by ~s.o.s~ View Post
  1. for (i=0;i<len1 && i<len2;i++) {
  2. if (str1[i] < str2[i])
  3. return 1;
  4. else if (str[i] > str2[i])
  5. return 2;
  6. }
  7. return 0 ;
  8. }

It should be something like: (not the exact implementation)

  1. {
  2. for (i=0;i<len1 && i<len2;i++) {
  3. if (str1[i] < str2[i])
  4. return str1 [i] - str2 [i] ;
  5. else if (str[i] > str2[i])
  6. return str1 [i] - str2 [i]; /* Forgot the semi-colon */
  7. }
  8. return 0 ;
  9. }

though I would even modify the loop to make it better, but then again, its okay.
This is not how string comparision function works. The string comparision functions returns the ASCII difference between the strings if they are unequal while a zero if they are equal.

Ok, it does not exactly work like that, however, please inform me on how returning 1, 2..... is newbie code? Why because I don't subtract them? Lol, ok. Wow what an advanced technique.

Originally Posted by ~s.o.s~ View Post
Why try to write a half baked comparision function when the library itself provides for its implementation.
Half baked, it works doesn't it? And because I don't subtract the difference, doesn't render the function half baked. That is absurd.
Last edited by Lazaro Claiborn; Mar 12th, 2007 at 11:33 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,620
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Problem in sorting by name

 
0
  #24
Mar 12th, 2007
> I'd really appreciate a link to a standard specification either for C (?) or for Daniweb, seriously.
It comes from practice. Just look around and read the code snippets and posts contributed by experienced people and you would know.

> Ok, it does not exactly work like that, however, please inform me on how returning 1, 2..... is
> newbie code? Why because I don't subtract them?

As for your implementation, read the actual specification of the strcmp function. Making your own functions which performs in a different way only adds to the confusion.
Last edited by ~s.o.s~; Mar 12th, 2007 at 11:38 pm.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 171
Reputation: Lazaro Claiborn is an unknown quantity at this point 
Solved Threads: 13
Lazaro Claiborn's Avatar
Lazaro Claiborn Lazaro Claiborn is offline Offline
Junior Poster

Re: Problem in sorting by name

 
0
  #25
Mar 12th, 2007
Originally Posted by ~s.o.s~ View Post
>
Making your own functions which performs in a different way only adds to the confusion.
Wow you've obviously got superior reasoning....:lol: Anyway, I guess I'll starting paying attention to such menial considerations. Regarding the programming suggestions I mean. Lol.
Last edited by Lazaro Claiborn; Mar 12th, 2007 at 11:43 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Problem in sorting by name

 
1
  #26
Mar 13th, 2007
Originally Posted by Lazaro Claiborn View Post
Originally Posted by joeprogrammer View Post
And this is just my opinion, but: I don't really see why using numbers in place of characters makes the code any clearer.
Yeah.... well it is a good thing it is your opinion. :lol:
Well, it's not just your opinion, Joe. I am in complete agreement that
if ((str[i] >= 'a' && str[i] <= 'z'))
is extremely more readable than
if ((str[i] >= 65 && str[i] <= 90))
And it will even work for code on EBCDIC machines... :p

I'd like to hear any dissenting opinion that is sensible...
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,442
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1474
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Problem in sorting by name

 
0
  #27
Mar 13th, 2007
Originally Posted by Lazaro Claiborn View Post
Here is another example program that might help you:
http://www.daniweb.com/code/snippet661.html
And just how do you expect a program that just displays "Hello World" is going to sort an array? :eek:
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 12
Reputation: lakshmi.1987 is an unknown quantity at this point 
Solved Threads: 0
lakshmi.1987 lakshmi.1987 is offline Offline
Newbie Poster

Re: Problem in sorting by name

 
0
  #28
Mar 14th, 2007
make use of string comparision function strcmp() and any sorting method.....its goin to be simple.....
if in case u r not able to device a solution..... i ll post u the code... try to understand it.....k....
Last edited by lakshmi.1987; Mar 14th, 2007 at 4:44 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC