Thread: strings strings strings str..

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    71

    strings strings strings str..

    Hi,
    I need to write a function that would scramble the alphabet (change the positions of random letters). I've written one but it's not working, and every time I change something seemingly irrelevant, I get different (always wrong) output..
    Could anyone please help?

    Thanks
    Linette

  2. #2
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    Smile Hmmm

    ive done one like this up at school, but the problem is a couple of the letters are weird lookin characters like ^&\ and stuff like that because what i did was something like this:


    #include <iostream.h>
    #include <fstream.h>

    int main()
    {
    ifstream infile;
    ofstream outfile;
    char ch;

    infile.open("A:/file.txt"); //letters you want scrambled here
    outfile.open("A:/scrambledfile.txt"); //use any .txt file

    while(! infile.fail())
    {
    infile.get(ch);
    if (ch==32||ch=='\n') //if its a space or endline
    {
    cout<<ch;
    outfile<<ch;
    }
    else
    {
    ch-=2;
    cout<<ch;
    outfile<<ch;
    }
    }
    outfile.close();
    infile.close();

    cout<<endl<<"Complete..."<<endl;

    return 0;
    }



    ok, theres a scramble program and it will scramble your file and it will look all funny...

    to unscramble it you could change:

    infile.open("scrambledfile.txt");
    outfile.open("descrambledfile.txt");

    and ch-=2; to ch+=2;

    yea i know the site says we wont make you your whole program, but i already made this one so im just helping...

    and i like to program

    hope that helps some...hey with that you could send messages to your friend and he can unscramble it...very secretive...

    edit<< i just re-read your post and it seems my program has nothing to do with what you want.. LOL
    Paro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New string functions
    By Elysia in forum C Programming
    Replies: 11
    Last Post: 03-28-2009, 05:03 AM
  2. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  3. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  4. need help with strings and str functions
    By Brokn in forum C Programming
    Replies: 7
    Last Post: 11-12-2005, 10:45 AM
  5. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM