update on the program - swaphalves() problem
I looked over my code and refined it as best I could. I pinpointed the problem to swaphalves(). my buffer read & write functions are ok.
for an input file content of: todo
(which is 4 bytes)
if i run read buffer function and swaphalves but don't call a buffer write, I get : tooto
when the result should be: toot
because a final write buffer should produce: odot
if I call write buffer now, i get: odoto
I can't make out where the extra character at the end comes from. Can you help me trace its source?
Here's the refined swaphalves code:
Code:
void swaphalves(char* buffer){
int nread = (int) readto; //counter to check EOF
int fend = (int) fsize; //indicates EOF
int byte; //tmp var to stor a byte
long back = -1L; //var for seeking back 1 byte
int revpos = (int) readto; //counter for reversing buffer contents
revpos--; //workaround as ((int) readto) - 1 gave bad result
while(((byte = fgetc(dfile)) != EOF) && (nread < fend)){
//loop to swap a byte from current file pos with current buffer pos
//put back last byte in buffer to file, seek back 1
fseek(dfile,back,SEEK_CUR);
fputc(buffer[revpos],dfile);
//file ptr will auto mov to original pos after call to fputc
//put latest byte read from file to end of buffer & decrement buffer position
buffer[revpos--] = (char) byte;
//get next byte in file in next while loop
nread++; //increment # bytes read indicator
}
return;
}
last, how might I go about moving a post to another forum say C++ without double posting?