neo programmer
- 4
- 0
hi! i was writing a program which asks the user to input the file name. the program then reads the file and prints out how many times each characeter has occurred in the file(uppercase and lowercase are different). Pls help me out.
this is what i have got-i know this is not correct.
#include<iostream>
#include<fstream>
#include<stdlib.h>
using namespace std;
int main()
{
fstream file_ptr;
char filename[81];
int a = 65;
int e=0;
char number[58]={0};
for(int i=0; i<58; i++)
{
number=a;
a++;
}
// Get name of file
count << "Enter filename : ";
cin.getline(filename,81);
// Open data file for READING
count << "Opening file "<< filename << endl;
file_ptr.open(filename, ios::in);
if (!file_ptr.good())
{
//The file could not be opened
count << "ERROR - file " << filename << " could not be opened";
exit(1);
}
// READ data from file until the end-of-file (EOF) is reached.
do {
file_ptr >> number;
count << "Read " << number << " from file." << endl;
} while(file_ptr.peek()!=EOF);
// Close file
count << "Closing file " << filename << endl;
file_ptr.close();
system("pause");
return 0;
}
this is what i have got-i know this is not correct.
#include<iostream>
#include<fstream>
#include<stdlib.h>
using namespace std;
int main()
{
fstream file_ptr;
char filename[81];
int a = 65;
int e=0;
char number[58]={0};
for(int i=0; i<58; i++)
{
number=a;
a++;
}
// Get name of file
count << "Enter filename : ";
cin.getline(filename,81);
// Open data file for READING
count << "Opening file "<< filename << endl;
file_ptr.open(filename, ios::in);
if (!file_ptr.good())
{
//The file could not be opened
count << "ERROR - file " << filename << " could not be opened";
exit(1);
}
// READ data from file until the end-of-file (EOF) is reached.
do {
file_ptr >> number;
count << "Read " << number << " from file." << endl;
} while(file_ptr.peek()!=EOF);
// Close file
count << "Closing file " << filename << endl;
file_ptr.close();
system("pause");
return 0;
}