Solving a Program to Break Words into Chunks

  • Context: Comp Sci 
  • Thread starter Thread starter newyorkNYC
  • Start date Start date
  • Tags Tags
    Break Program
Click For Summary

Discussion Overview

The discussion revolves around a programming homework problem involving reading lines from a file and breaking them into smaller chunks of ten characters each. Participants explore potential approaches to parsing the input data and structuring the output.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant requests guidance on how to approach the problem without needing complete code, indicating a desire for pointers or strategies.
  • Another participant asks for the current progress on the problem to better assist.
  • A participant expresses feeling stumped and indicates that previous attempts have not been successful.
  • One suggestion involves reading the input file as strings and parsing them into chunks, noting that the term "chunks" could refer to either individual strings or arrays.
  • A proposed solution includes using a struct to hold the words and a count of occurrences, along with pseudo code outlining steps for reading the file, checking for duplicates, and writing the output.

Areas of Agreement / Disagreement

Participants have not reached a consensus on a specific solution, and multiple approaches to parsing and structuring the data are being discussed.

Contextual Notes

The original problem statement lacks detail regarding the exact requirements for "chunks" and how to handle duplicates, which may affect the proposed solutions.

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

Replies
8
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 6 ·
Replies
6
Views
4K
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K