#include<stdio.h>
#include <string.h>
int main()
{
/*The output file*/
FILE *fo;
/*The input file*/
FILE *fi;
/*The current character we are on*/
char c[2];
c[1]=0;
/*The array to build the word we are on*/
char *s=malloc(900000);
/* Opens the file for reading */
fi=fopen("d.txt","r");
c[0]=getc(fi);
/* While loop responsible for reading current character,
creating the string of directories linked to that character
, and placing the word at the end*/
while(c[0]!=EOF)
{
strcat(s,"lib\\");
/*While loop that checks the current char for a space or a newline*/
while((c[0]!=' '&&c[0]!='\n'))
{
strcat(s,c);
strcat(s,"\\");
c[0]=getc(fi);
}
printf(s);
/*Makes the directory following the string of characters (IE: Character would be c\h\a\r\a\c\t\e\r)*/
mkdir(s);
s=malloc(9000);
c[0]=getc(fi);
}
return 0;
}
编辑:
事实证明,解决方案是这样的:
char *s=(char* )malloc(600);
...
while(c[0]!=EOF)
{
strcpy(s,"lib");
...
strcat(s,"\\");
strcat(s,c);
...
mkdir(s,0777);
printf(s);
s=(char* )realloc(s,600);
但是,这样做并不能解决没有通过 mkdir 语句创建目录的问题。修改了大多数错误,唯一的问题是减少完成所有内容所需的时间,并首先创建它应该创建的目录。