Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,080 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,584 people online right now. Registration is fast and FREE... Join Now!




Count symbols

 
Reply to this topicStart new topic

Count symbols

cooplis
14 Apr, 2008 - 04:41 AM
Post #1

D.I.C Head
**

Joined: 11 Sep, 2007
Posts: 77


My Contributions
Can someone tell me why this won't count the * symbol? The program is done except for that.

CODE

#include <ctype.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <cstdlib>

using namespace std;

void add_plus_plus(ifstream& in_stream, ofstream& out_stream);


int main( )
{
ifstream fin;
ofstream fout;
char ch;

int count = 0;
int isalpha;
int isspace;

cout << "Begin editing files.\n";
fin.open("E:\\textin.txt");
if (fin.fail( ))
{
cout << "Input file opening failed.\n";
system ("pause");
exit(1);
}
fout.open("E:\\textOut.txt");
if (fout.fail( ))
{
cout << "Output file opening failed.\n";
system ("pause");
exit(1);
}

add_plus_plus(fin, fout);


fin.close( );
fout.close( );
cout << "End of editing files.\n";
system ("pause");
}
void add_plus_plus(ifstream& in_stream, ofstream& out_stream)
{
    char next, ch;
    int isalpha = 0;
    int isspace = 0;
    
    in_stream.get(next);
    while (!in_stream.eof( ))
    {
        if  (next == '-')
            ch = ' ';
        else if (isupper(next))
            ch = tolower(next);
        else if (isdigit(next))
            ch = '*';
        else ch = next;
        out_stream << ch;

      
        if (next == ch)
           isalpha++;

        if (next == ('.'))
        isspace++;
        
         if (next == ('*'))
        isspace++;
        
        if (next == (' '))
        isspace++;
        
        in_stream.get(next);

    }

    
   cout << "\nNumber of letters: " << isalpha <<endl;
     cout << "Number of spaces: " << isspace <<endl;
}





Thanks,

Everybody
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 07:30PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month