//////////////////////////////////////////////////////////////////////////////////
// Now I have an idea how to get my strings from the file so that I can properly
// play with them (with fstream I did not have the string "in my clutches" quite
// the way I wanted it). However, now I have a problem with my looping because
// this way, I am seeing the last line *TWICE* in my output, so feof must trigger
// from the error caused by reading past the end of the file or what just is the
// reason?
//
// Is there an elegant way to exit from this? My first thought was to use a
// do {...} while; but that does not solve it either. Maybe if there was a
// do { ... } until; Oh well. Maybe someone will have an idea? I am sure that
// I don't have a firm grip on this.
//
// Thank You for Your Kind indulgence (bad case of the newbies!).
//
// 73
// -Grace
// NNNN
// z
//////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#define BUFFERSIZE 256 // Make sure lines will not be longer than this
char LineBuffer[BUFFERSIZE];
int main ()
{
FILE* outfile = fopen("MyOuput.txt", "w");
FILE* infile = fopen("ReadWriteLine.cpp", "r");
// infile is this file since it changes and it's fun
while (!feof(infile))
{
fgets(LineBuffer, BUFFERSIZE, infile);
// lines will be truncated if longer than BUFFERSIZE
printf("%s", LineBuffer); // now output to console
fprintf(outfile, "%s", LineBuffer); // and our file
}
fclose(infile);
fclose(outfile);
system("PAUSE");
return(0);
}
//////////////////////////////////////////////////////////////////////////////////
// -eof- (This line is output *TWICE*)