当前位置: 代码迷 >> C语言 >> 高手请指点 :这个程序运行不出来运行
  详细解决方案

高手请指点 :这个程序运行不出来运行

热度:241   发布时间:2005-12-19 19:26:00.0
高手请指点 :这个程序运行不出来运行

请高手们指点一下,这个程序欲得到当前硬盘中的分区数(即硬盘有几个分区)?及如何遍历分区中的文件.请看看有什么错误 怎么改正

//很有趣的目录程序,有一点乱,你自己看啦
#include<my.h>//关于*.h的集合,自己可以还原
#include<time.h>
#include<dir.h>
#include<dirent.h>
#include<string.h>
#define star_x 20
#define star_y 4
typedef struct dir_me{
struct ffblk file;
struct dir_me *left;
struct dir_me *right;
int sign;
}d_me;
char file_name_xxx[13]={"*.*"};
d_me *head_dir,*u,*tail_dir;
typedef struct dir_ch{
struct ffblk file;
int sign,*num_1;
}d_ch;
d_ch dir_now[17];
void init_mouse();
void mouse_IQR(int *num,int *bx,int *cx,int *dx);
void put_mouse_position(int *x,int *y);
void cursor();
int rightb_pressed();
int leftb_pressed();
int box_sign,mouse_x,mouse_y,dir_num,MAX,color_sign,jd_sign,jd_sign1,ii;
char now_dir[88];// dir of doing now
//****************************** FIND DIR************************
void get_now_dir(void)
{
getcwd(now_dir,88);
}
void get_dir1(void)
{
DIR *dir;
char file_name1[88];
struct dirent *ent;
struct ffblk file;
register int done;
int i;
char name[13];
dir=opendir(now_dir);
chdir(now_dir);
done=findfirst(file_name_xxx,&file,0);
head_dir=tail_dir=NULL;
MAX=0;
while(! done)
{
MAX++;
u=(d_me*)malloc(sizeof(d_me));
u->file=file;
u->sign=2;
u->left=NULL;
u->right=NULL;
if(head_dir==NULL) tail_dir=head_dir=u;
else {
tail_dir->right=u;
u->left=tail_dir;
tail_dir=u;
}
done=findnext(&file);
}
if(head_dir==NULL)
{
u=(d_me*)malloc(sizeof(d_me));
strcpy(u->file.ff_name,"..");
u->sign=3;
u->left=NULL;
u->right=NULL;
tail_dir=head_dir=u;
}
while((ent=readdir(dir))!=NULL)
{
u=head_dir;
while((stricmp(u->file.ff_name,ent->d_name))&&(u!=NULL)) u=u->right;
if((u==NULL)&&(strcmp(ent->d_name,"."))){
MAX++;
u=(d_me*)malloc(sizeof(d_me));
u->file=head_dir->file;
if(!strcmp(ent->d_name,"..")) u->sign=3;
else u->sign=1;
u->left=tail_dir;
tail_dir->right=u;
u->right=NULL;
for(i=0;i<13;i++)
u->file.ff_name[i]=ent->d_name[i];
tail_dir=u;
}
}
i=MAX/8;
if(MAX<8) i++;
MAX=i;
closedir(dir);
}
int get_dir2(int *num)
{ int i,j;
d_me *uu;
uu=head_dir;
for(i=1;i<*num;i++)
for(j=0;j<8;j++){
uu=uu->right;
if(uu==NULL) return 0;//do nothing
}
for(i=1;i<17;i++){
if(uu!=NULL){
dir_now[i].file=uu->file;
dir_now[i].sign=uu->sign;
}
else{
for(;i<17;i++)
dir_now[i].sign=0;
return 1;
}
uu=uu->right;
}
return 1;
}
//************************************ find dir end*****************
//************************************ about mouse**********************
void init_mouse()
{
int num=0;
mouse_IQR(&num,&num,&num,&num);
// num++;
// mouse_IQR(&num,&num,&num,&num);
if(num!=0){
printf("Mouse not installed!");
exit(1);
}
}
void mouse_IQR(int *num,int *bx,int *cx,int *dx)
{
union REGS r;
r.x.ax=*num;
r.x.bx=*bx;
r.x.cx=*cx;
r.x.dx=*dx;
int86(0x33,&r,&r);
*bx=r.x.bx;
*cx=r.x.cx;
*dx=r.x.dx;
}
void put_mouse_position(int *x,int *y)
{
int button=0,num;
num=3;
cursor();
mouse_IQR(&num,&button,x,y);
}
void put_mouse(void)
{
int *x,*y;
int button=1,num;
num=2;
cursor();
mouse_IQR(&num,&button,x,y);
}

void cursor()
{
int num=1;
mouse_IQR(&num,&num,&num,&num);
}
int rightb_pressed()
{
int bx=0,num;
num=3;
mouse_IQR(&num,&bx,&num,&num);
return bx&2;
}
int left_pressed()
{
int bx=0,num;
num=3;
mouse_IQR(&num,&bx,&num,&num);
return bx&1;
}
int mouse_in(int x,int y,int x1,int y1)
{
put_mouse_position(&mouse_x,&mouse_y);
if(((mouse_x/8)>=--x)&&((mouse_x/8)<=--x1)&&((mouse_y/8)>=--y)&&((mouse_y/8)<=--y1))
return 1;
else return 0;
}
int mouse_left_2(void)
{
int i;
for(i=0;i<2;i++){
delay(100);
if(left_pressed()==1) return 1;
}
return 0;
}

//********************************* mouse end****************************
//********************************* //textwindow********************//***
void windo(int x1,int y1,int x2,int y2,int color_1,int color_2)
{
window(x1,y1,x2,y2);
textbackground(color_1);textcolor(color_2);clrscr();
gotoxy(1,1);
}
int key_1(int x1,int y1,int x2,int y2,int color_1,int color_2,int color_3,int color_4,char *str_1[20])
{ int i,j,K=1;
textbackground(color_2);textcolor(color_1);
window(x1,y1,x2,y2);
clrscr();gotoxy(1,1);
cprintf("%s",str_1[0]);
textbackground(color_4);textcolor(color_3);
window(x2+1,y1,x2+2,y1);cprintf("%c",i=220);
window(x2+1,y1,x2+2,y2);j=y2-y1+1;
for(;j>1;j--){
gotoxy(1,++K);
cprintf("%c",i=219);}
window(x1+1,y2+1,x2+2,y2+1);clrscr();gotoxy(1,1);
j=x2-x1+1;
for(;j>0;j--)
cprintf("%c",i=223);
return 1;
}
void dis_dir(int *num)
{ int i,j;
// get_dir1();
int time_e,date_e,time_b,date_b;
int time_f,time_m,time_sh,date_n,date_y,date_r;
time_t t;
get_dir2(num);
windo(star_x+3,star_y+6,star_x+17,star_y+13,11,0);
for(i=1;i<9;i++){
if(dir_now[i].sign){
if(i==color_sign){textbackground(2);textcolor(15);}
else{textbackground(11);textcolor(0);}
gotoxy(1,i);
cprintf(" ");
gotoxy(1,i);
cprintf(" %s",dir_now[i].file.ff_name);
if(dir_now[i].sign==1) cprintf("\\");
if(dir_now[i].sign==3) {gotoxy(2,i);cprintf("..\\");}
}
}
windo(star_x+19,star_y+6,star_x+33,star_y+13,11,0);
for(i=1;i<9;i++){
if(dir_now[i+8].sign){
if((i+8)==color_sign){textbackground(2);textcolor(15);}
else{textbackground(11);textcolor(0);}
gotoxy(1,i);
cprintf(" ");
gotoxy(1,i);
cprintf(" %s",dir_now[i+8].file.ff_name);
if(dir_now[i+8].sign==1) cprintf("\\");
if(dir_now[i+8].sign==3) {gotoxy(2,i);cprintf("..\\");}
}
}
windo(star_x+1,star_y+16,star_x+48,star_y+17,1,11);
cprintf(" %s\\%s",now_dir,file_name_xxx);
gotoxy(1,2);
cprintf(" %s",dir_now[color_sign].file.ff_name);
gotoxy(17,2);
cprintf(" %ld",dir_now[color_sign].file.ff_fsize);
gotoxy(25,2);
cprintf("%c",dir_now[color_sign].file.ff_fsize);
time_e=dir_now[color_sign].file.ff_ftime;
date_e=dir_now[color_sign].file.ff_fdate;
time_b=time_e;date_b=date_e;
time_m=(time_b&31)*2;
time_b>>5;
time_f=time_b&63;
time_e>>11;
time_sh=time_e&31;
date_r=date_b&31;
date_b>>5;
date_y=date_b&15;
date_e>>12;
date_n=(date_e&15)+1990;
gotoxy(25,1);cprintf("Date:%d,%d,%d",date_y,date_r,date_n);
gotoxy(30,2);cprintf("Time:%d:%d:%d",time_sh,time_f,time_m);
windo(star_x+3,star_y+3,star_x+30,star_y+3,1,11);
cprintf(" %s\\%s",now_dir,file_name_xxx);

}
void dis_jd(void)
{
int i,j;
windo(star_x+4,star_y+14,star_x+33,star_y+14,11,1);
for(i=1;i<29;i++) cprintf("%c",j=178);
textbackground(1);
textcolor(11);
gotoxy(1,1);cprintf("%c",j=17);
gotoxy(29,1);cprintf("%c",j=16);
if(ii<MAX) {
gotoxy(jd_sign,1);cprintf("%c",j=254);}
else{
gotoxy(28,1);cprintf("%c",j=254);}
put_mouse();
}

void main(void)
{
char *key_one[20]={" Open"};
char *key_twe[20]={" Replace"};
char *key_three[20]={" Cancel"};
char *key_fore[20]={" Help"};
char *key_name[20]={" Name"};
char *key_file[20]={" Files"};
int my_key;
int i,j,k,num_2;
get_now_dir();
get_dir1();
textmode(3);
init_mouse();
color_sign=1;
windo(star_x,star_y,star_x+49,star_y+18,7,15);
for(i=1;i<50;i++) {
gotoxy(i,1);
printf("%c",j=205);
gotoxy(i,19);printf("%c",j=205);
}
for(i=1;i<20;i++){
gotoxy(1,i);
printf("%c",j=186);
gotoxy(50,i);
printf("%c",j=186);
}
gotoxy(1,1);printf("%c",j=201);gotoxy(50,1);printf("%c",j=187);
gotoxy(1,19);printf("%c",j=200);gotoxy(50,19);printf("%c",j=188);
gotoxy(46,1);printf("%c",j=91);textcolor(4);cprintf("%c",j=88);textcolor(15);
printf("%c",j=93);gotoxy(19,1);printf(" Open a File ");
put_mouse_position(&mouse_x,&mouse_y);
key_1(star_x+36,star_y+3,star_x+45,star_y+3,11,2,0,7,key_one);
key_1(star_x+36,star_y+6,star_x+45,star_y+6,11,2,0,7,key_twe);
key_1(star_x+36,star_y+11,star_x+45,star_y+11,11,2,0,7,key_three);
key_1(star_x+36,star_y+14,star_x+45,star_y+14,11,2,0,7,key_fore);
key_1(star_x+2,star_y+2,star_x+12,star_y+2,15,7,7,7,key_name);
windo(star_x+3,star_y+3,star_x+30,star_y+3,1,11);
key_1(star_x+2,star_y+5,star_x+12,star_y+5,15,7,7,7,key_file);
windo(star_x+3,star_y+6,star_x+33,star_y+14,11,14);
for(i=1;i<10;i++){
gotoxy(16,i);
textcolor(1);
cprintf("%c",j=179); }
windo(star_x+1,star_y+16,star_x+48,star_y+17,1,11);
jd_sign=2;
jd_sign1=27/MAX;
ii=1;
dis_dir(&ii);
dis_jd();
while(1){
my_key=0;
if(left_pressed()==1){
if(mouse_in(star_x+4,star_y+14,star_x+4,star_y+14)) {my_key=1000;
if(ii>1) {ii--; jd_sign-=jd_sign1;dis_jd();dis_dir(&ii);}}
if(mouse_in(star_x+32,star_y+14,star_x+32,star_y+14)) {my_key=1001;
if(ii<MAX) {ii++;jd_sign+=jd_sign1;dis_jd();dis_dir(&ii);}}
if(mouse_in(star_x+36,star_y+3,star_x+45,star_y+3)) {my_key=100;
key_1(star_x+36,star_y+3,star_x+45,star_y+3,7,7,7,7,key_one);
key_1(star_x+37,star_y+3,star_x+46,star_y+3,11,2,7,7,key_one);
put_mouse();
delay(200);
key_1(star_x+36,star_y+3,star_x+45,star_y+3,11,2,0,7,key_one);
if(dir_now[color_sign].sign==3){
i=87;
while(now_dir[i]!='\\') i--;
if(now_dir[i-1]==':') now_dir[i+1]='\0';
else now_dir[i]='\0';
get_dir1();
ii=1;
jd_sign=2;
jd_sign1=27/MAX;
dis_jd();
dis_dir(&ii);
}
if(dir_now[color_sign].sign==1){
if(now_dir[3]!='\0')
strncat(now_dir,"\\",1);
strncat(now_dir,dir_now[color_sign].file.ff_name,13);
get_dir1();
ii=1;
jd_sign1=27/MAX;
jd_sign=2;
dis_jd();
dis_dir(&ii);
}
}
if(mouse_in(star_x+36,star_y+6,star_x+45,star_y+6)) {my_key=200;
key_1(star_x+36,star_y+6,star_x+45,star_y+6,7,7,7,7,key_twe);
key_1(star_x+37,star_y+6,star_x+46,star_y+6,11,2,7,7,key_twe);
put_mouse();
delay(200);
key_1(star_x+36,star_y+6,star_x+45,star_y+6,11,2,0,7,key_twe);
}

if(mouse_in(star_x+36,star_y+11,star_x+45,star_y+11)) {my_key=300;
key_1(star_x+36,star_y+11,star_x+45,star_y+11,7,7,7,7,key_three);
key_1(star_x+37,star_y+11,star_x+46,star_y+11,11,2,7,7,key_three);
put_mouse();
delay(200);
key_1(star_x+36,star_y+11,star_x+45,star_y+11,11,2,0,7,key_three);
}
if(mouse_in(star_x+36,star_y+14,star_x+45,star_y+14)) {my_key=400;
key_1(star_x+36,star_y+14,star_x+45,star_y+14,7,7,7,7,key_fore);
key_1(star_x+37,star_y+14,star_x+46,star_y+14,11,2,7,7,key_fore);
put_mouse();
delay(200);
key_1(star_x+36,star_y+14,star_x+45,star_y+14,11,2,0,7,key_fore);
}
if(mouse_in(star_x+3,star_y+5,star_x+17,star_y+13)||mouse_in(star_x+19,star_y+5,star_x+33,star_y+13))
{
i=mouse_y/8-8;
if(mouse_x/8>36) i+=8;
if(i!=my_key) {
my_key=i;
color_sign=my_key;
dis_dir(&ii);
put_mouse();
}
if(mouse_left_2()) {
if(dir_now[color_sign].sign==3){
i=87;
while(now_dir[i]!='\\') i--;
if(now_dir[i-1]==':') now_dir[i+1]='\0';
else now_dir[i]='\0';
get_dir1();
ii=1;
jd_sign=2;
jd_sign1=27/MAX;
dis_jd();
dis_dir(&ii);
}
if(dir_now[color_sign].sign==1){
if(now_dir[3]!='\0')
strncat(now_dir,"\\",1);
strncat(now_dir,dir_now[color_sign].file.ff_name,13);
get_dir1();
ii=1;
jd_sign1=27/MAX;
jd_sign=2;
dis_jd();
dis_dir(&ii);
}
}
}
if(mouse_in(star_x+3,star_y+3,star_x+30,star_y+3)) {my_key=500;
}
if((mouse_x==520)&&(mouse_y==24))
break;}
delay(100);
}
}


搜索更多相关的解决方案: 运行  

----------------解决方案--------------------------------------------------------
  相关解决方案