i have to write a program that will read in a txt file that also has periods, exclamations, question marks and <CR>(returns). and do some other stuff. right now i am having trouble with comparing the words..... this is at the very bottom of my code

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

const int MAX_LINE=201;
const int MAX_WIDTH=21;
void showcontent(fstream &);
int main()
{
	fstream dataFile;
	dataFile.open("data.txt", ios::in);

	char line[MAX_LINE][MAX_WIDTH];
	char ch;
	int i=0;
	int j=0;
	int length;
	int count=0;
	int add=0;
	int counter[MAX_LINE];

	dataFile.get(ch);
	while(!dataFile.eof())
	{
		cout << ch;
		if(isalpha(ch))
		{
			ch=tolower(ch);
			line[i][j]=ch;
			j++;
		}
		else
		{
			line[i][j]=NULL;
			i++;
			j=0;
		}
		dataFile.get(ch);
	}
	cout << endl;

	for(int m=0; m<i; m++)
	{
		for(int n=0; n<i; n++)
		{
			if(line[m] == line[n])
			{
				counter[add]=count++;
			}
		}
		cout << line[m] << endl;
		cout << counter[add] << endl;
		add++;
		count=0;
	}

	return 0;
}

>>for(int n=0; n<i; n++)

should that be n < j ?

Also what exactly is the problem?

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.