Thread: Help with a Decoder!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    You want to 'map' each character in the alphabet to your own 'encoding'.

    1) Read in the first line in your file
    2) Iterate over each character in the line
    3) Store each character in an array that represents a character mapping
    4) Read and decode the remaining lines

    I want to guess you do not know how many lines are in the file. Don't use an array of strings like you have done, instead use a vector<string>.
    The >> operator will read 1 token at a time (i.e. one word), instead use getline(stream, str).



    A nice way to hold your 'mapping' is to use an array.
    Imagine you want to map the letter 'f' to the letter 'g'.
    We can do the following:
    Code:
    char * map = new char[26];
    map['f' - 'a'] = 'g';
    Now you can hold a mapping you each 26 characters, each accessible using a single array. (We subtract 'a' so that the character 'f' is turned into a number between 0 and 25)
    Last edited by rodrigorules; 09-09-2012 at 09:36 PM.
    Check out my programming / algorithm blog @ http://www.swageroo.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. packet decoder in C
    By eshoja in forum C Programming
    Replies: 2
    Last Post: 06-05-2012, 11:42 AM
  2. Help with a resistor decoder
    By usernameisvalid in forum C Programming
    Replies: 5
    Last Post: 06-25-2011, 05:21 PM
  3. Mpeg2 decoder
    By thangdc01_02 in forum C Programming
    Replies: 6
    Last Post: 11-21-2010, 04:09 PM
  4. decoder
    By jalenamichelle in forum C++ Programming
    Replies: 1
    Last Post: 11-03-2010, 06:24 AM
  5. MP3 Decoder
    By Pete in forum Projects and Job Recruitment
    Replies: 4
    Last Post: 05-02-2005, 08:35 AM

Tags for this Thread