View Single Post
Join Date: Dec 2008
Posts: 18
Reputation: da penguin is an unknown quantity at this point 
Solved Threads: 5
da penguin's Avatar
da penguin da penguin is offline Offline
Newbie Poster

Re: sorting characters in a string... help!!!!

 
0
  #3
Jan 1st, 2009
Look, you have that #include<string.h> right? So why don't you use c++ strings? It's like
  1. string str;
  2. str = "whatever"
and it's easier.
Now this
  1.  
  2. for(int b=0;b<=(strlen(a)-1);b++)
  3. {
  4. for(int c=0;c<=(strlen(a)-2);c++)
  5. {
  6. if(strcmp(a[c],a[c+1])<0) //I DON"T THINK THIS IS RIGHT
  7. {
  8. strcpy(temp,a[c]);
  9. strcpy(a[c],a[c+1]);
  10. strcpy(a[c],temp);
  11. }
  12. }
  13. }

is a mess. You could just compare a[c] < a[c+1] cuz this are characters, not strings and they are already sorted in ASCII.

Could you please explain what the program is supposed to do?
No, ma'am, we are musicians.
Reply With Quote