I created a text file. Write 5 byes('ABCDE') to the file. After closing the file... I want to delete its last character('E') by reading all file contents and recreating a new one with same filename. Is it possible to do this in just one time 'fopen()'? Facing with problems when the file size is too big, large buffer used and very slow. My code as below

[cpp]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void create_file()
{
char str[] = {"ABCDE"};
FILE *fp = fopen("c:\\try.txt", "wb");
fwrite(str, 1, strlen(str), fp);
fclose(fp);
}
void remove_last()
{
long fsize;
char *buf = NULL;
// Read file contents...
FILE *fp = fopen("c:\\try.txt", "r+b");
fseek(fp, 0, SEEK_END);
fsize = ftell(fp);
fseek(fp, 0, SEEK_SET);
buf = (char*)malloc(fsize);
fread(buf, 1, fsize, fp);
fclose(fp);
// Reopen the file...
fp = fopen("c:\\try.txt", "wb");
fwrite(buf, 1, fsize - 1, fp);
fclose(fp);
free(buf);
}
void main()
{
create_file();
remove_last();
}
[/cpp]
-novice
