G
Guest
How can I identify a carriage return in C++?
\r, \f, \0, \n, \t does not work. I have also tried !isprint(ch), iscntrl(ch), isspace(ch), etc....with no luck!
I even poked around in the MSDN and found some code that MS claims will save a file in unix format and I cut and pasted into my program(and made changes to suit):
.....
char ch;
char temp[MAX_PATH]="\0";
//Open the file for reading in binarymode.
ifstream fp_read(filename.c_str(), ios_base::in
| ios_base::binary);
if(!fp_read)
cout << "could not open " << filename.c_str() << endl;
else
cout << "opened for read: " << filename.c_str() << endl;
sprintf(temp, "%s.temp", filename.c_str());
//Create a temporary file for writing in the binary mode. This
//file will be created in the same directory as the input file.
ofstream fp_write(temp, ios_base:
ut
| ios_base::trunc
| ios_base::binary);
if(!fp_write)
cout << "could not open fp_write" << endl;
else
cout << "opened fp_write " << endl;
while(fp_read.eof() != true)
{
fp_read.get(ch);
//Check for CR (carriage return)
if((int)ch == 0x0D)
continue;
if (!fp_read.eof())fp_write.put(ch);
}
fp_read.close();
fp_write.close();
//Delete the existing input file.
remove(filename.c_str());
//Rename the temporary file to the input file.
rename(temp, filename.c_str());
//Delete the temporary file.
remove(temp);
.....
This does not work either.
Is there a sequence of characters that can be used to compare to a MS carriage return?
Thanks
Laura
\r, \f, \0, \n, \t does not work. I have also tried !isprint(ch), iscntrl(ch), isspace(ch), etc....with no luck!
I even poked around in the MSDN and found some code that MS claims will save a file in unix format and I cut and pasted into my program(and made changes to suit):
.....
char ch;
char temp[MAX_PATH]="\0";
//Open the file for reading in binarymode.
ifstream fp_read(filename.c_str(), ios_base::in
| ios_base::binary);
if(!fp_read)
cout << "could not open " << filename.c_str() << endl;
else
cout << "opened for read: " << filename.c_str() << endl;
sprintf(temp, "%s.temp", filename.c_str());
//Create a temporary file for writing in the binary mode. This
//file will be created in the same directory as the input file.
ofstream fp_write(temp, ios_base:

| ios_base::trunc
| ios_base::binary);
if(!fp_write)
cout << "could not open fp_write" << endl;
else
cout << "opened fp_write " << endl;
while(fp_read.eof() != true)
{
fp_read.get(ch);
//Check for CR (carriage return)
if((int)ch == 0x0D)
continue;
if (!fp_read.eof())fp_write.put(ch);
}
fp_read.close();
fp_write.close();
//Delete the existing input file.
remove(filename.c_str());
//Rename the temporary file to the input file.
rename(temp, filename.c_str());
//Delete the temporary file.
remove(temp);
.....
This does not work either.
Is there a sequence of characters that can be used to compare to a MS carriage return?
Thanks
Laura