Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: C++ problem

  1. Jan 16, 2010 #1
    1. The problem statement, all variables and given/known data

    Hello, I am having trouble with this program. I would not need a complete code.. but instead just some words that would point me in the correct direction.. or how you would go about solving it.

    This is the problem.

    The file contains lines like the following.

    ABCThese are some words that must
    ABCbe broken down into smaller chuncks.
    XYZMore words
    XYZthat must be put into chunks.

    So basically output file look like:
    ABC01These are
    ABC02some words
    ABC03 etc

    etc. so each one consists of ten characters.

    Any pointers?
  2. jcsd
  3. Jan 16, 2010 #2


    Staff: Mentor

    Show us what you have so far.
  4. Jan 16, 2010 #3
    Kind of stumped actually. Everything ive tried seems to fail.

    Ill post when I got something valuable.
  5. Jan 16, 2010 #4
    It seems you would read in the file input as strings and devise your own simple way to parse those strings.
    Also your problem you have provided is lacking some detail, all your telling us is you need to read in some file data and put them into "chunks", by chunks you could have meant two things judging from what your output file is supposed to be like, chunks being each string you've read in parsed into new variable or chunks of array, from your post of output file seems to be an array it seems like you can benefit from using a simple array of structs, where your struct contains two variables string word, int wordCount; once again judging from your posts here is some pseudo code to possible help you

    Code (Text):

    //Declare your struct here

    //In main
     //Declare your array of struct objects
    //You choosing to be dynamic, or static if you know the amount of input coming in
    //Open file
    //Go through file placing new strings into array
    //Inside of reading the data in, iterate through the current array elements
    //If your current item read in already exists in the array, do not add it and increment the count of how many items that item was in the input //file

    //Place all items into the array with no checking
    //After data has been  read in, iterate through the array checking if an array element has a duplicate else where in the array if so increment //duplicate count

    //Close input file
    //Write output to wilte
    Last edited: Jan 16, 2010
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook