The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Output number of rows inserted, updated... kushal_cog UNIX for Dummies Questions & Answers 0 01-30-2008 03:28 AM
CEP as sauce for alphabet soup (Part 9): ETL iBot Complex Event Processing RSS News 0 11-24-2007 09:41 PM
adding order number in the output file happyv Shell Programming and Scripting 20 03-13-2007 01:12 AM
How to count number of occurrences of a "|" from a variable? jingi1234 UNIX for Dummies Questions & Answers 4 05-06-2005 05:48 PM
What can i do to check that the input is all alphabet.. ? XXXXXXXXXX Shell Programming and Scripting 4 02-19-2002 07:09 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 12-02-2007
svd svd is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 6
output the letters of the alphabet with the number of occurrences

hi,
I'm trying to create a program that will read a file and then check the file for each letter of the alphabet and then output the letter and the number of times it appears in the file, into a new file... this is what i have so far but it's not working.. if anyone could help that would be nice!
thanks

#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;

int main()
{
cout << "\n To find the number of occurrences of each letter in the alphabet in a specific file,"
<< "enter the file name:";
string inFile;
cin >> inFile;

cout << "\nEnter the name of the output file:";
string outFile;
cin >> outFile;

ifstream fin(inFile.data());
assert (fin.is_open());
ofstream fout(outFile.data());
assert (fout.is_open());

vector<int> numoccurrences(26);
int i;
char letter;
for(;
{
fin >> letter;
char lowercase = tolower(letter);
if ('a'<= lowercase <='z')
numoccurrences[ lowercase - 'a']++;
}
char ch = 0;
for (int i = 1; i < numoccurrences.size(); i++)
{
fout << ch << numoccurrences[i];
ch++;
}
}
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0