Google PlusFacebookTwitter

Text File – No Uppercase

By on Sep 5, 2007 in On A Whim |

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 – Convert file contents to uppercase and copy to another file */

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

void main()
{
clrscr();
fstream obj(“text.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(“text.txt”, ios::in);
fstream obj2(“new.txt”, ios::out);
while ( !obj.eof() )
{
ch = obj.get();
ch = (char)toupper(ch); // type-casting while conversion
obj2<<ch;
}
obj.close();
obj2.close();
cout<<endl<<“New file is”<<endl;
obj2.open(“new.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 ANSWER TO LIFE, THE UNIVERSE, AND EVERYTHING IS 42