I'm trying to code a sentence editor. So, basically the input comes form a file, and the code sorts the words. The input in the file is I not do know, theoutput is I do not know.

This is what's gonna be in the input file, but it can be anything:

This is is an an icorrect sntence.

Input Output (on the screen)
delete("is",2)
print 1:This 2:is 3:an 4:an 5:icorrect 6:sntence
delete("an",3)
print 1:This 2:is 3:an 4:icorrect 5:sntence
delete("icorrect",4)
print 1:This 2:is 3:an 4:sntence
insert("incorrect",4)
print 1:This 2:is 3:an 4:incorrect 5:sntence
delete("sntence",5)
insert("sentence",5)
print 1:This 2:is 3:an 4:incorrect 5:sentence
neighbors("is") 2:is previous:This next:an

= This is an incorrect sentence.

The input sentence (possibly a paragraph) is maintained as a doubly linked list. Each node will store a word. The print command send output to the screen. Each word must have its position in the list in format position:word. Words in the list must be separated by one space. And I should assume that there's no maximum number of lines in the input file.

I want to use array based lists/linked lists. Can somebody give me heads up to get started? I already looked at array based lists/linked lists, but it's confusing to me.

Easy enough. What you need to do is the following :

1) Populate the list with words from the file.
2) Start from the beginning, check if the first word is correct, i.e first letter is capitalized, and spelled correctly.
3) Check if the second word is spelled correclty, if not fix it
4) Check if the second word is now the same as the first word, if so delete it
5) Repeat until the end of the list, for each word in the list.

So, for step one I just creaste an array and get the info from the file. How do I populate the array with the info from the file?

#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}

And then I gotta get the data into the array. How'd I do this?

since you dont know what the size of the file will be i would suggest using a container from the STL. that said i will use a vector for my example.

vector<string> words;
string word;
ifstream fin("text.txt")  // use ifstream object to get info from file
while (fin >> word) // will read until there is no more info in the file
    words.push_back(word);  // add the word to the vector

Thanks. That makes more sense. I know how to populate an arry by user input, but I don't know how to populate if the data comes from a text file.

Hm, nobody?

Considering Nathan showed you how, I suppose no one deemed it necessary to respond...

commented: thanks +2

K.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.