От: | zorky | ||
Дата: | 16.01.09 11:52 | ||
Оценка: |
#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);
}