- 注册时间
- 2005-8-2
- 最后登录
- 1970-1-1
|
可以封装成库
//to find a word from the end of a string,return the position in the string
char findword(char &string[],char word)
{
int i;
for(i=strlen(string);i>0;i--)
{
if(string[i-1]==word)break;
}
return (i-1);
}
//if choose a file return 1 else return 0
char choose(char &namebuf[])
{
char path[15];
char i;
memset(path,0,15);
ChDir("/");
for(;;)
{
if(!FileList(path)||!strcmp(path,".."))
{
if(namebuf[0]==0)return 0;
ChDir("..");
namebuf[findword(namebuf,'/')]=0;
continue;
}
strcat(namebuf,"/");
strcat(namebuf,path);
if(!ChDir(path))break;
}
return 1;
}
void main()
{
char buf[64];
choose(buf);
SetScreen(1);
printf("%s",buf);
getchar();
} |
|