论坛: 编程破解 标题: 文件问题(C) 复制本贴地址    
作者: sniper167 [sniper167]    论坛用户   登录
原本是想往硬盘上不停的写东西,可是最多只能写15个文件(从0到14),不解,请问是何原因?(显示can not open the file)

#include <stdlib.h>
#include <stdio.h>
main()
{
FILE *fp;
char str[20],str1[10];
char *p=str1;
int i;
gets(str);
for (i=0;;i++)
      {itoa(i,p,10);
      if ((fp=fopen(p,"w"))==NULL)
          {printf("Can not open the file\n");
            exit(0);
          }
      else fprintf (fp,"%s",str);
      }
fclose(fp);
getch();
}


地主 发表时间: 04-03-29 23:07

回复: yingzike [yingzike]   论坛用户   登录
DOS下吧?
文件句柄不够用了。

SET FILE=10000



B1层 发表时间: 04-03-30 14:19

回复: sniper167 [sniper167]   论坛用户   登录
改成这样就可以了写65535个文件了,不过还有个问题没有解决:就是怎样超过65535个,因为文件名由i的值来定,i从-32768---32767,然后又循环,又开始在同一个文件里写同一个内容,要在65535个文件内塞满硬盘,就必须增大文件。。。

#include <stdlib.h>
#include <stdio.h>
main()
{
FILE *fp;
char str[20],str1[10];
char *p=str1;
int i;
gets(str);
for (i=0;;i++)
      {itoa(i,p,10);
      if ((fp=fopen(p,"w"))==NULL)
          {printf("Can not open the file\n");
            exit(0);
          }
      else fprintf (fp,"%s",str);
      fclose(fp);
      }
getch();
}



[此贴被 啥都不会(sniper167) 在 03月30日21时20分 编辑过]

B2层 发表时间: 04-03-30 21:02

回复: yingzike [yingzike]   论坛用户   登录
int i;  ?????

改成 unsigned long int i;

就会多一点了,同时

set file = 1000000;



B3层 发表时间: 04-03-31 11:02

回复: sniper167 [sniper167]   论坛用户   登录
set file = 1000000;

这句啥意思?起啥作用?

B4层 发表时间: 04-04-01 10:27

回复: yingzike [yingzike]   论坛用户   登录
======================================================
for (i=0;;i++)
      {itoa(i,p,10);

      if ((fp=fopen(p,"w"))==NULL)
          {printf("Can not open the file\n");
            exit(0);
          }
      else fprintf (fp,"%s",str);

      }
fclose(fp);
===============================================

改成这样看看,打开一个关闭一下

  else fprintf (fp,"%s",str);

     
fclose(fp);

}


另: SET FILE = 10000;
是指在DOS下可以打开的文件句柄数

B5层 发表时间: 04-04-01 10:50

回复: sniper167 [sniper167]   论坛用户   登录
对呀
是那样的(解决了只能写15个文件的问题)

我想用while (1)
        {・・・・
        }
可是文件又怎样来命名呢?还是要用i的递增

B6层 发表时间: 04-04-01 11:10

回复: yingzike [yingzike]   论坛用户   登录
记得C中有个随机产生绝不会和当前目录下重名的文件的函数的
你找找看
其实这种方法填硬盘空间也太有点不经事
还不如想想其他方法,不过我没有,呵呵


B7层 发表时间: 04-04-01 12:39

回复: kailangq [kailangq]   版主   登录


B8层 发表时间: 04-04-02 04:05

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号