4 Replies - 471 Views - Last Post: 22 April 2010 - 04:20 PM Rate Topic: -----

#1 ROAR08  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-April 10

read characters from an input file, & output to a 2nd file

Posted 22 April 2010 - 02:00 PM

Im trying to write a program that reads characters from an input file, and outputs to another file the number of each character used, like A - 15, B - 12 etc...I can use no more than 2 if statements, and I have to use an array of structs. Im not sure what else to say. Here is the code Ive gotten so far. I know it is terrible but I am new so please be patient.

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

struct letters
{
	int uppercase;
	int lowercase;
};

void getUserInput(string& inputFile, string& outputFile);
void openFile(ifstream& fin, ofstream& fout, string& inputFile, string& outputFile);
void count(letters getLetters[52], string& inputFile);
void printResult(letters getLetters[52], string& outputFile);
void closeFile(ifstream& fin, ofstream& fout, string& inputFile, string& outputFile);
void initializeArray(letters findLetters[52]);

int main()
{
	letters findLetters[52];
	



	
	return 0;
}

void getUserInput(string& inputFile, string& outputFile)
{
	cout << "Please enter the name of the input file: " << endl;
	cin >> inputFile;

	cout << "Please enter the name of the output file: " << endl;
	cin >> outputFile;
	
	return;
}

void openFile(ifstream& fin, ofstream& fout, string& inputFile, string& outputFile)
{
	fin.open(inputFile);
	fout.open(outputFile);
	
	return;
}
void closeFile(ifstream& fin, ofstream& fout, string& inputFile, string& outputFile)
{
	fin.close();
	fin.close();
	
	return;
}

void initializeArray(letters findLetters[52])
{
	for(int i=0;i<52;i++)
	{
		findLetters[i] = 0;
	}


void count(letters getLetters[52], string& inputFile)
{
	int counter = 0;

	while(!fin.eof())
	{
		counter++;
	}
		
	for(int i=0;i<counter;i++)
	{
		fin >> 
}



Is This A Good Question/Topic? 0
  • +

Replies To: read characters from an input file, & output to a 2nd file

#2 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5379
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: read characters from an input file, & output to a 2nd file

Posted 22 April 2010 - 02:01 PM

** Renamed title to be more descriptive of topic **
Was This Post Helpful? 0
  • +
  • -

#3 Enter_Kratos  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 72
  • Joined: 26-September 09

Re: read characters from an input file, & output to a 2nd file

Posted 22 April 2010 - 02:57 PM

What exactly do you mean by

Quote

the number of each character used
?

I originally thought you were after the decimal representation of the letter from the ascii table but there are no legible characters that low down.

Please explain a little more.

Kratos
Was This Post Helpful? 0
  • +
  • -

#4 ROAR08  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-April 10

Re: read characters from an input file, & output to a 2nd file

Posted 22 April 2010 - 03:13 PM

View PostEnter_Kratos, on 22 April 2010 - 01:57 PM, said:

What exactly do you mean by

Quote

the number of each character used
?

I originally thought you were after the decimal representation of the letter from the ascii table but there are no legible characters that low down.

Please explain a little more.

Kratos

sorry, what i mean is: 1.) i need to count each time a particular letter is used, but not just any letter, i need to count each time EVERY letter is used, lower and upper case, for instance, the word Bobby would need to output as 1 upper case B, 1 lower case o, 2 lower case b, 1 lower case y, it just has to count each time every letter is used, my professor said that we should be able to incorporate the ascii values of the letters to help write the program
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6091
  • View blog
  • Posts: 23,605
  • Joined: 23-August 08

Re: read characters from an input file, & output to a 2nd file

Posted 22 April 2010 - 04:20 PM

Here is the ASCII table, so that's where would go to find out what are the ASCII values of characters. It's a good starting point. You need to come up with the algorithm for keeping track of the count. This is an EXTREMELY common problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1