Thread: Word unscrambling

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    19

    Word unscrambling

    I was wondering how to make a program that would;

    1) Read a text file with about ten scrambled words in it, seperated by a line each.

    2) Somehow unscrable the words using a wordlist given to me by my tutor, which contains some random words (eg. s4t4sff)

    3) Finally, output all of them to a text file, in the form "firstword secondword thirdword etc"

    I have been trying to do this for a while now but have failed.

    Thanks in advance.

    P.S - I have searched the forums numerous times, but haven't really found anything that specific. Thanks again.

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Colchester, Essex, United Kingdom.
    Posts
    31
    Tell us more about the order of the words once the sorting has finished. Do they need to be in alphabetical order, or some other order?

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    They have to be in the order in which they are written in the text file. For example, the jumbled words would be like this;

    word1

    word2

    word3

    And unscrambled would have to look like this;

    word1 word2 word3

    Thanks for your fast reply!
    Last edited by pukebucket; 01-07-2006 at 09:41 AM.

  4. #4
    Registered User
    Join Date
    Dec 2005
    Location
    Colchester, Essex, United Kingdom.
    Posts
    31
    Your confusing me. In that example, the words are not scrambled. Do you mean something like this:

    file.txt - (scrambled)
    cat
    animal
    bear

    new_file.txt - (unscrambled)
    animal
    bear
    cat


    That would be in alphabetical order...

  5. #5
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    eg. s4t4sff
    Erm that's not a word.

  6. #6
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    I'm sorry, this is what I mean.

    File.txt (scrambled)
    atc
    malnia
    erab

    new_file.txt(unscrambled)

    cat animal bear

    I agree it's confusing, I told my tutor that but he insists

  7. #7
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Okay, to do that you need instructons from a file so that your program knows how to unscramble.

    If not, this would work:

    Loop it to switch every two letters. For an example:

    Code:
     int i; 
    char storage;
    for(i = 1; i < FILE_SIZE; i = i + 2)
    {
      if(((FileBuffer[i] == ' ') || (FileBuffer[i] == '\0')) || ((FileBuffer[i - 1] == ' ') || (FileBuffer[i - 1] == '\0')))
    	continue;
      storage = FileBuffer[i] + 0; 
      FileBuffer[i] = FileBuffer[i - 1] + 0;
      FileBuffer[i - 1] = storage + 0;
    }
    It might need a little more help but that should get you started.

    So now this:
    noe wto htere ofru ifev isx esevn iehgt inen ten

    Would look like this:
    one two three four five six seven eight nine ten

    Hope that helps, August.
    Last edited by Queatrix; 01-07-2006 at 10:14 AM.

  8. #8
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Are you allowed to check it against a common dictionary file?

  9. #9
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    Thats exactly what I mean

    To Treenef - Yes I know, I meant they are random charactors. I should have explained it better. And he gave me a text file with all the unjumbled "words" (if you can call them that) in it. There are thousands in there.

  10. #10
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Ok, so what ideas do you have, I've done this before, but seeing as this is homework, you're going to have to do most of the work.


    One other thing. To make this absolutely clear, are there any numbers in the list such as the examples provided by Cool-August?


    Code:
    file.txt - (scrambled)
    owr1d
    w2odr
    
    new_file.txt - (unscrambled)
    word1 word2
    Last edited by treenef; 01-07-2006 at 10:12 AM.

  11. #11
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    Well, I know how to read strings from a text file using something like
    Code:
     ifstream b_file
    But it only reads the first string. I don't know how to make it go to the next one after it has done the first one.

    I also know have a low level of understanding how to find all possible combinations of letters from a string. Like tree would be
    tree, eert, tere, teer etc. I found this using search.

    He also said something like : "make it into an array of null terminated strings." as a hint.

    P.S - Yes there are. Some aren't even real words, like 45nws3 and some are just numbers like; 45225
    Last edited by pukebucket; 01-07-2006 at 10:21 AM.

  12. #12
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Try somthing like this:

    Code:
    char word[MAX_WORD_SIZE][FILE_SIZE];
    ifstream b_file;
    int i;
    for(i =0; i < FILE_SIZE; i++)
    b_file.in >> word[i];

  13. #13
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    P.S - Yes there are. Some aren't even real words, like 45nws3.

    Ok, and what is the length of the largest word in your file?
    This is a very important question, because you would either be using a permutation generator or a letter frequency counter.

  14. #14
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    The biggest word is 15 charectors.

    Thanks for your help people, it is very appreciated.

  15. #15
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Ok since the largest word is of length 15 it means you cannot use a permuation generator...

    Do you know what a letter frequency counter is?

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. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 07:55 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Wrong Output
    By egomaster69 in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 06:44 PM
  5. Using 'if' with char arrays or string objects
    By c++_n00b in forum C++ Programming
    Replies: 36
    Last Post: 06-06-2002, 09:04 PM