C++ Input File reading help!!!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 1
Reputation: beast0000 is an unknown quantity at this point 
Solved Threads: 0
beast0000 beast0000 is offline Offline
Newbie Poster

C++ Input File reading help!!!

 
0
  #1
Dec 31st, 2008
Hello guys,

I am new in this forum and i hope im gonna get some fast help.

I have this problem where i should input numbers from a .doc file, and the program should output how many times the number of occurences of each number.

ie: the numbers in the .doc file are 2,3,6,8,9,2,1,1,3,1.

The program should read the numbers from the file and outputs the following:
Number 1 = 3
Number 2 = 1 ... and so on.

I started with the following but im getting stuck.
Any help please??

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

int main()
{
int array[10000];
ifstream numbers( "numbers.doc", ios::in);
if(!numbers)
{
cerr << endl << "File could not be opened" << endl;
system("pause");
exit(1);
}

for (i=0, i<10000, i++)
array[i] = 0; //initializes array

for (i=0, i<50, i++)
{
if (i=1)
array[n] += array[i];
cout << array[i];
}
{
if (i=2)
array[n] += array[i];
cout << array[i];
}
///and so on.

I appreciate any suggestions and assistance,

Thank u
Last edited by beast0000; Dec 31st, 2008 at 1:48 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 960
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: C++ Input File reading help!!!

 
0
  #2
Dec 31st, 2008
Site rules, "CODE TAGS!"

The usual structure I suggest often, to avoid the whole emergency bail out thing.
  1. file open
  2. if(file.is_open())
  3. {
  4. do stuff here;
  5.  
  6. file.close();
  7. }
  8. else
  9. {
  10. cout << "Error!";
  11. }
You probably should place those loops in a function too.
Where is i declared?

You need to format it and place it in code tags, I got lost, and was sure I saw something funky with the brackets after the second for loop.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC