Google PlusFacebookTwitter

Text Files – No Words Starting With Vowels

By on Sep 5, 2007 in On A Whim | 0 comments

Share On GoogleShare On FacebookShare On Twitter

/* Copyright (C) 2007 Ankur Banerjee. This program is free software: you can redistribute it and / or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. For a copy of the GNU General Public License see http://www.gnu.org/licenses/gpl.html */

/* Text Files – Copy those words which do not start with a vowel to a new file from an existing file */

#include <fstream.h>
#include <stdio.h>
#include <conio.h>

void main()
{
clrscr();
fstream obj(“text1.txt”, ios::out);
char s[101], ans, ch;
do
{
cout<<endl<<“Enter data (max 100 characters) : “;
gets(s);
obj<<s<<‘\n’;
cout<<“Do you wish to continue (y / n) : “;
cin>>ans;
} while (ans == ‘y’);
obj.close();
obj.open(“text1.txt”, ios::in);
fstream obj2(“text2.txt”, ios::out);
while ( !obj.eof() )
{
obj.getline(s, 101, ‘ ‘);
switch (s[0])
{
case ‘A’ :
case ‘a’ :
case ‘E’ :
case ‘e’ :
case ‘I’ :
case ‘i’ :
case ‘O’ :
case ‘o’ :
case ‘U’ :
case ‘u’ : break;
default : obj2<<s<<‘\n’;
}
}
obj.close();
obj2.close();
cout<<endl<<“New file is :”<<endl;
obj2.open(“text2.txt”, ios::in);
while ( !obj2.eof() )
{
ch = obj2.get();
cout<<ch;
};
obj2.close();
getch();
}

/* Output */

Enter data (max 100 characters) :
The Answer to Life, the Universe, and Everything is 42
Do you wish to continue (y / n) : n

New file is :
The
to
Life,
the
42



Submit a Comment

Your email address will not be published. Required fields are marked *