| | |
String Sorting Help
![]() |
•
•
Join Date: Oct 2007
Posts: 49
Reputation:
Solved Threads: 0
c++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; void main () { char *tokenString, *c, string[80]; cout << "Input a string: "; cin.getline(string, 80); cout << "The entered string is: " << string << endl; c = string; while (*c) { if ((*c >= 'a') && (*c <= 'z')) *c = (*c - 'a') + 'A'; ++c; } cout << "The string in all upper case letters is: " << string << endl; tokenString = string; char *tokenPtr, *nullPtr= NULL; cout << "The string to be tokenized is:\n" << tokenString << "\n\nThe tokens are:\n"; tokenPtr = strtok( tokenString, " " ); while ( tokenPtr != NULL ) { cout << tokenPtr << '\n'; tokenPtr = strtok(nullPtr, " " ); } }
1) i am trying to get user to input a list of words and then i need to:
* sort them in alpha orders
* and display how many time each word is present in the string. ignore case. for ex: bob == BOB
2) my current code can takes a string input and convert all the words in the string into upper case and tokenized them into parts.
3) i need help on how to compare each of the tokenized words and see if they are equal.
4) samples of ideal inputs and outputs i need my code to do
input
bill bill joe jack dan bob BILL BOB
output
BILL BOB DAN JACK JOE
BILL 3
BOB 2
DAN 1
JACK 1
JOE 1
THANKS
Here is the standard way to convert a string to upper case
After tokenizing the string you need to put them in an array so that you can search the array for a string.
C++ Syntax (Toggle Plain Text)
while (*c) { *c = toppper(*c); ++c; }
After tokenizing the string you need to put them in an array so that you can search the array for a string.
Last edited by Ancient Dragon; Dec 10th, 2007 at 4:07 pm.
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.
>>How do i compare the strings to check if any words are the same?
strcmp()
>>also how should put the tokenized string into a array, a loop?
strcmp()
>>also how should put the tokenized string into a array, a loop?
C++ Syntax (Toggle Plain Text)
char *array[255] = {0}; // room for 255 strings int i = 0; ... array[i] = tokenPtr;
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.
![]() |
Similar Threads
- very strange string behaviur.. (C)
- Reverse String? (Java)
- sorting from a input text file (C)
- String sorting troubles (C++)
- sort string in file txt (C++)
- sorting an array of string (C)
- sorting 2d arrays (C)
Other Threads in the C++ Forum
- Previous Thread: Is there a way to prevent creating objects on heap?
- Next Thread: Calc end and loop?
| Thread Tools | Search this Thread |
action api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node noob output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets






