#include <stdio.h>
void main()
{ FILE *f;
char *str1="abc\r\n";
char *str2="123\r\n";
char s;
int res;
int pos;
// part one
f=fopen("test.txt","wb");
fwrite(str1,5,1,f);
fclose(f);
// part two
f=fopen("test.txt","rb+");
// move cursor to end line
while(1)
{ res=fread(&s,1,1,f);
if (res==0)
break;
if(s=='\n')
{ break;
}
}
pos=ftell(f);
// if uncomment this - will OK
// fseek(f,0,SEEK_END);
// pos=ftell(f);
res=fwrite(str2,1,5,f);
if (res==0)
{ printf("What's a problem?\n");
}
fclose(f);
}
Здравствуйте, zorky, Вы писали:
Z>...
Из документации MSDN по функции
fopen:
When the "r+", "w+", or "a+" access type is specified, both reading and writing are allowed (the file is said to be open for "update"). However, when you switch between reading and writing, there must be an intervening fflush, fsetpos, fseek, or rewind operation. The current position can be specified for the fsetpos or fseek operation, if desired.