怎么创建有大小的空文件?
我用下面的 不行呀.
FILE* f = fopen("d:/d.txt","ab");
if (f)
{
int iret = fseek(f,1024 * 1024 * 1024 - 1,SEEK_SET);
fwrite("",1,1,f);
fclose(f);
}
[解决办法]
msdn:
When a file is opened with the "a" or "a+" access type, all write operations occur at the end of the file. The file pointer can be repositioned using fseek or rewind, but is always moved back to the end of the file before any write operation is carried out.
你一旦写EOF的时候就回到原位置了。行不通的,可用其他方法变通下实现
[解决办法]
#include<stdio.h>
void main(int argc,char *argv[])
{FILE *fp=fopen("h:/d.txt","ab+");
int a=0,b,i;
while(getc(fp)!=EOF)
a++;
for(i=1;i<1024*1024-a;i++)
putc(0,fp);
fclose(fp);
}
比较笨,但感觉实现了你说的、、、