- 论坛徽章:
- 0
|
Linux下测试结果
[root@linux wuqing]# more filetest.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
FILE *fp;
char buf[20];
if((fp=fopen("./test.txt","a+"))==NULL)
{
printf("open test.txt error\n");
exit(-1);
}
fseek(fp,0,SEEK_SET);
memset(buf,0,sizeof(buf));
fread(buf,5,1,fp);
printf("buf = %s\n",buf);
memset(buf,0,sizeof(buf));
strcpy(buf,"this is a test");
printf("buf 2 = %s\n",buf);
fprintf(fp,"%s\n",buf);
fclose(fp);
exit(0);
}
[root@linux wuqing]# gcc -o filetest filetest.c
[root@linux wuqing]# more test.txt
123456789
[root@linux wuqing]# ./filetest
buf = 12345
buf 2 = this is a test
[root@linux wuqing]# more test.txt
123456789
this is a test
[root@linux wuqing]#
[ 本帖最后由 wuqing 于 2006-10-10 15:12 编辑 ] |
|