Comp Sci Solving a Program to Break Words into Chunks

  • Thread starter Thread starter newyorkNYC
  • Start date Start date
  • Tags Tags
    Break Program
AI Thread Summary
The discussion centers on a programming challenge involving breaking lines of text from a file into smaller chunks of ten characters each. Participants suggest reading the file as strings and parsing them into an array of structs, where each struct contains a word and a count of occurrences. There is a focus on handling duplicates by either checking during input or after all data has been read. The conversation emphasizes the need for clarity in the problem statement and encourages sharing progress for further assistance. Overall, the thread aims to provide guidance on structuring the code to achieve the desired output format.
newyorkNYC
Messages
1
Reaction score
0

Homework Statement



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.
123Ya

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

etc. so each one consists of ten characters.

Any pointers?
 
Physics news on Phys.org
Show us what you have so far.
 
Kind of stumped actually. Everything I've tried seems to fail.

Ill post when I got something valuable.
 
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:
//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

Or
//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:

Similar threads

Back
Top