C++ Books
The only problem I have with char*''s is I don''t know how to pass them into different functions.
also I'm supposed to make a program that will read characters from a file and print them omitting all e's. So this is what i have.
#include <iostream.h>
#include <fstream.h>
#include <assert.h>
void main()
{
char ch;
ifstream infile;
infile.open("new");
assert (!infile.fail());
while(!infile.fail())
{
infile.get(ch);
if((ch !='e') || (ch!='E'))
cout << ch;
}
infile.close();
}
The only problem with it is it displays the whole string including all the E's which doesn't make sense.
[edited by - Lorek on May 7, 2003 12:42:40 AM]
#include <iostream.h>
#include <fstream.h>
#include <assert.h>
void main()
{
char ch;
ifstream infile;
infile.open("new");
assert (!infile.fail());
while(!infile.fail())
{
infile.get(ch);
if((ch !='e') || (ch!='E'))
cout << ch;
}
infile.close();
}
The only problem with it is it displays the whole string including all the E's which doesn't make sense.
[edited by - Lorek on May 7, 2003 12:42:40 AM]
if((ch !=''e'') || (ch!=''E''))
Go thru this in your head or on paper. Suppose ch == ''e''.
Then ch != ''E''.
if((ch !=''e'') && (ch!=''E''))
I think this is what you wanted - a common mistake.
Go thru this in your head or on paper. Suppose ch == ''e''.
Then ch != ''E''.
if((ch !=''e'') && (ch!=''E''))
I think this is what you wanted - a common mistake.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement