Word Unscrambler

This is a discussion on Word Unscrambler within the C++ Programming forums, part of the General Programming Boards category; Hey folks, I've been working on this project for quite some time today, prolly around like 3 hours and it ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    20

    Word Unscrambler

    Hey folks, I've been working on this project for quite some time today, prolly around like 3 hours and it should be such a simple task!
    Basically it reads a wordlist (wordlist.txt) and a scrambled wordlist (encrypted.txt). As for preparation I've only included one string in each file that contains the same thing. Check this out:

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    int main()
    {
        unsigned int i =0;
        unsigned int chardex =0;
        unsigned int chardexE =0;
        string decrypt_str;
        string current_str;
        string encrypt_str;
    
        fstream wordlist("wordlist.txt",ios::in);
        fstream encrypted("encrypted.txt",ios::in);
        fstream decrypted("decrypted.txt",ios::out);
        fstream log("log.txt",ios::out);
        if(wordlist.is_open() && encrypted.is_open() && decrypted.is_open())
        {
            while(!wordlist.eof())
            {
                getline(wordlist,current_str);
                getline(encrypted,encrypt_str);
    
                log << "This prints whatever i want it to...yet..."
    
                if(current_str.length() == encrypt_str.length())
                {
                    log << "THIS DOES NOT PRINT! and they are equal fasho."
    
                    for(chardex=0;chardex<=current_str.length();chardex++)
                    {
                        for(chardexE=0;chardexE<=current_str.length();chardexE++)
                        {
                           if(current_str[chardex] == encrypt_str[chardexE])
                           {
                                decrypt_str[chardex] == encrypt_str[chardexE];
                                printf("decrypt[%i] = encrypt[%i]",chardex,chardexE);
                                decrypted << decrypt_str[chardex];
    
                            }
                        }
                    }
                }
    
            }
            encrypted.close();
            decrypted.close();
            log.close();
        }
        else{
            printf("Cannot open the files");
        }
        wordlist.close();
        return 0;
    }
    Logically this is probably about 80% done, but I can't get anything to work after the .length() issue! Nothing prints so I'm pretty sure nothing happens. Any clue guys?

    Thanks in advance

    EDIT: btw I'm using GCC Compiler in Ubuntu
    Last edited by fl00d; 09-28-2009 at 02:49 AM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Print out the lengths. What do you think they are, and what does the machine think they are?

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    20
    Okay so I added these two lines:

    Code:
    getline(wordlist,current_str);
                getline(encrypted,encrypt_str);
    
                log << "wordlist: " << current_str << " Length:" << current_str.length(); //here
                log << "wordlist: " << encrypt_str << " Length:" << encrypt_str.length(); //and here :)
    and I'm beginning to get somewhere....I'll be back haha

    thanks for the quick response man big ups

    EDIT: Okay now I added a +1 to encrypt_str.length()....and its beginning to work
    Last edited by fl00d; 09-28-2009 at 03:18 AM.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You started out good, but your post didn't actually ask anything. "I've got two lists... and some code." That's pretty much all your post said. Next time, actually ask a question, or explain what you want and how that's different from what you're getting. Ask smart questions.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. Word Unscrambler
    By fl00d in forum C++ Programming
    Replies: 1
    Last Post: 06-16-2008, 12:46 PM
  3. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 07:55 PM
  4. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  5. Wrong Output
    By egomaster69 in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 05:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21