Hey Narue!
I need ur help on a upper-lower case switch problem..
Read the contents of a text file (using ifstream class)..
and create a new file or edit the same one (using ofstream class)
to switch the case of each char (upper to lower & vice versa)..

Thanks a bunch in advance

below is the code i tried but not working:

#include<iostream>
#include<fstream>
#include<cctype>
using namespace std;


int main()
{
ofstream lang("Batch6.txt");
lang<<"Pogram Name Shripal Parekh"<<endl;
lang<<"hELLO wORLD";
cout<<"File Created!\n";
lang.close();

ofstream newfile("SwitchedCases.txt");
ifstream rlang("Batch6.txt");
while(!rlang.eof())
{
char ch=rlang.get();
if(isalpha(ch))
{
if(islower(ch))
{
newfile<<(char)toupper(ch);
}
else
{
newfile<<(char)tolower(ch);
}
}
else
{
cout<<' ';
}
newfile.close();
}
return 0;
}

what is currently happening when you run this?

plz to add code tags to you code

@Phoenix:
It creates the 1st file: "Batch 6.txt" with the specified text..
The case switching works fine.. (I checked by using cout to get the output..)

But the 2nd file: "SwitchedCases.txt" gets create, without the desired output..

Hey Narue!

Why can't I have groupies? I'm sure she'll be thrilled with the shout-out.

Anyway... look at line 36 in relation to your while loop. Walk yourself through a cycle or two of the loop, noting when the file gets closed.

lol.. sorry didn mean 2 direct the thread at Narue alone.
(it was supposed 2 b reply to a post but i ended up creatin a new thread)..
anyways, u're ryt!! my silly mistake :(
was closing the file inside the loop..
thank u very very much :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.