| | |
sorting characters in a string... help!!!!
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
•
•
help here again... if i enter AaBbCc the output should be CcBbAa or cCbBaA.. but the output appears cbaCBA.. help!!! heres the code..
#include<iostream.h> #include<conio.h> #include<string.h> #include<stdio.h> #include<search.h> //int joke(const void* x,const void* y); void main() { clrscr(); char a[100],temp; cout<<"Enter string: "; cin>>a; for(int i=(strlen(a)-1);i>=0;i--) cout<<a[i]; cout<<"\n\nLETTERS IN THE STRING: "; for(int b=0;b<(strlen(a)-1);b++) { for(int c=b+1;c<(strlen(a));c++) { if(a[b]<a[c]) { temp=a[b]; a[b]=a[c]; a[c]=temp; } } } cout<<a; getch(); }
C++ files don't have .h, so it's <iostream>. Important to remember, since <string.h> is very different from <string>.
Also try C++'s string with built in functions of convenience.
Place your sorting method in a function to clear things up a tad.
Use newlines to space out parts of your code.
main() must return zero.
clrscr(), is that portable?
Now as Vernon recommended, just need to compare it in one case then flip it back keeping track of it with a boolean statement.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
![]() |
Similar Threads
- Sorting Strings (Java)
- Bubble sorting (Java)
- Hi, everyone I need Help in MIPS random string (Assembly)
- Open In New Window Php (PHP)
- Vectors, Functions, and Sorting... oh my! (C++)
- sorting an array of string (C)
- sorting 2d arrays (C)
Other Threads in the C++ Forum
- Previous Thread: Segmentation Default Error when Initializing Class object
- Next Thread: quick synax question
Views: 1352 | Replies: 12
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





