X-WM-Posted-At: MailAndNews.com; Mon, 27 Aug 01 13:29:08 -0400 X-WebMail-UserID: Ramiman12 Date: Mon, 27 Aug 2001 13:29:08 -0400 Sender: Ramy Elmeligy From: Ramy Elmeligy To: djgpp AT delorie DOT com X-EXP32-SerialNo: 50000000 Subject: RE: Program, uses compare() to check for anagrams, but doesnt work Message-ID: <3B8AEFEF@MailAndNews.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Mailer: InterChange (Hydra) SMTP v3.61.08 Reply-To: djgpp AT delorie DOT com Sorry about that last message, i was insanely frustrated, next time ill be more clear. The good news is, now the program compiles fine, thanks to Hans' tip(surprised i didnt catch that, its happened to me before). However, upon compilation, the program does what it should up to the line that says "Lets see if your strings are anagrams of each other." Then it does an endl and shows a blinking cursor, and the program doesnt do anything after that. I'm effectively stuck as to what to do, since there are two for() loops and an if() statement after this which should be executed. I'll repost the source, since ive made some changes, and besides, i dont think anyone values my emails enough to store them :) <----------------------------------------------------------------------------- -> //Exercise - Anagram Checker #include #include using namespace std; int main() { string input1; string input2; cout << "Enter a line of text: "; getline(cin, input1); cout << endl; cout << "Enter another line of text: "; getline(cin, input2); cout << endl; cout << "Let's see if your strings are anagrams of each other. " << endl; int greater = 0; int lesser = 0; if(input1.length() > input2.length()) { greater = input1.length(); lesser = input2.length(); } else { greater = input2.length(); lesser = input1.length(); } int equal = 0; int a = 0; int b = 1; int c = 0; equal = input1.substr(a, b).compare(input2, c, b); for( ; c < lesser ; ) { for( ; a < greater, equal == 0 ; a++) { input1.substr(a, b).compare(input2, c, b); } if(a >= greater) { a = 0; c++; } } if(input1.substr(a, b).compare(input2, c, b) != 0) { cout << "The strings are not anagrams."; return 0; } else { cout << "The strings are anagrams! What luck!"; return 0; } } ------------------------------------------------------------ Get your FREE web-based e-mail and newsgroup access at: http://MailAndNews.com Create a new mailbox, or access your existing IMAP4 or POP3 mailbox from anywhere with just a web browser. ------------------------------------------------------------