- Joined
- Jul 25, 2001
- Location
- Austin, tx, usa
i have two problems with some programs i have to write for class. The prompt for the problem is
Write a program that prompts the user for the name of a text file and reports the number of characters in the text file and the number of end line characters in the file.
ia m having trobble with the end line part if somone could better explain to me ofstream.h and maybe even show me a sample of how to do this it would be apperciated.
here is my code:
#include <iostream.h>
#include <fstream.h>
char name;
main()
{
long count = 0;
long total = 0;
long count2 = 0;
long total2 = 0;
char y ;
char x ;
char name[500];
ifstream infile;
cout<< "enter the name of a text file:" <<" ";
cin.get(name, 500);
infile.open(name,ios::in);
{
do
{
infile >> x;
if(!infile.eof())
{
count ++;
}
if (count>total);
{
total=count;
}
}while (!infile.eof());
cout << count << endl;
}
infile.close();
infile.open(name,ios::in);
{
do
{
infile >> y;
if((!infile.eof())||(y=='\n'));
{
count2 ++;
}
if (count2>total2);
{
total2=count2;
}
}while (!infile.eof());
cout << total2;
}
infile.close();
return 0;
}
Write a program that prompts the user for the name of a text file and reports the number of characters in the text file and the number of end line characters in the file.
ia m having trobble with the end line part if somone could better explain to me ofstream.h and maybe even show me a sample of how to do this it would be apperciated.
here is my code:
#include <iostream.h>
#include <fstream.h>
char name;
main()
{
long count = 0;
long total = 0;
long count2 = 0;
long total2 = 0;
char y ;
char x ;
char name[500];
ifstream infile;
cout<< "enter the name of a text file:" <<" ";
cin.get(name, 500);
infile.open(name,ios::in);
{
do
{
infile >> x;
if(!infile.eof())
{
count ++;
}
if (count>total);
{
total=count;
}
}while (!infile.eof());
cout << count << endl;
}
infile.close();
infile.open(name,ios::in);
{
do
{
infile >> y;
if((!infile.eof())||(y=='\n'));
{
count2 ++;
}
if (count2>total2);
{
total2=count2;
}
}while (!infile.eof());
cout << total2;
}
infile.close();
return 0;
}