有人可以帮我解决这个问题吗?有错误,但我对此有些困惑. [英] can anyone help me w/ this problem? There is an error but im bit confused on it..

查看:61
本文介绍了有人可以帮我解决这个问题吗?有错误,但我对此有些困惑.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

--- im很难解决很多错误---

---im having difficult to fix the error alots of them---

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<dir.h>
#include<dos.h>

struct node
{
 char *name;   /* used to get file / folder name. */
 int attrib;   /* used to get it's attribute.  */
 struct node *next;  /* concept of Linked list */
};
int main()
{
 struct node *head,*head1;
 struct node *list,*list1;
 struct node * place(struct ffblk ff,struct node *first,int don);
 void display(struct node *first);
 void print(struct node *list,int *i);
 int i,c,c1,done,done1;
 struct ffblk, ff,f1;
 head=NULL;
 head1=NULL;
 //clrscr();
 done=findfirst("*.*",&ff,FA_DIREC|FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH);
 /* struct variable "f" contains all files and folders information */
 done1=findfirst("*.*",&f1,FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH);
 /* struct variable "f1" contains all files information */
 head=place(f,head,done);  /* content of f is placed in struct head */
 display(head);
 /*
  Note : f contains name of files and folders with their attributes
  in f.ff_name, f.ff_attrib which is assigned to name, attrib in
  the struct node
 */
 printf("*************************************************");
 getch();
 head1=place(f1,head1,done1); /* content of f1 is placed in struct head1
*/
 display(head1);
 /*
  Note : f1 contains name of files and folders with their attributes
  in f1.ff_name, f1.ff_attrib which is assigned to name, attrib in
  the struct node
 */
 printf("*************************************************");
 getch();
 i=0;
 c1=0;
 /*
  Here, head and head1 are compared so that we could extract only
  the folders.
 */
 list=head;   /* head is assigned to list */
 while(list!=NULL)
 {
   list1=head1;  /* head1 is assigned to list1 */
   if(list1==NULL)   /* if there are 0 files */
    print(list,&i);   /* then display content of list */
   else
   {
    while(list1!=NULL)
    {
    if(strcmp(list-&gt;name,list1-&gt;name)==0)  /* compare list and list1 */
     c1=1;
    list1=list1-&gt;next;
    }
    if(c1==0)      /* if folder found both in list and list1*/
     print(list,&i);  /* then display content of list */
   }
   c1=0;
   list=list-&gt;next;
  }
 printf("		 FOLDERS = %d",i);
 printf("*************************************************");
 printf("		Where,");
 printf("		H - Hidden");
 printf("		D - Directory");
 printf("		R - Read only");
 printf("		S - System");
 printf("		A - Archive");
 getch();
 free(list1);
 free(list);
 free(head);
 free(head1);
}

void print(struct node *list,int *i)
{
 void property(struct node *list);
 /* to display folders other than default folders (. and ..)  */
 if((strcmp(list-&gt;name,"."))!=0 && (strcmp(list-&gt;name,".."))!=0)
 {
  *i=*i+1;     /* counts number of folders */
  property(list);
  printf(" %s",list-&gt;name);
 }
}

void property(struct node *list)
{    /* finds their attribute */
  if(list-&gt;attrib & FA_HIDDEN)
   printf("(H)");
  if(list-&gt;attrib & FA_DIREC)
   printf("(D)");
  if(list-&gt;attrib & FA_RDONLY)
   printf("(R)");
  if(list-&gt;attrib & FA_SYSTEM)
   printf("(S)");
  if(list-&gt;attrib & FA_ARCH)
   printf("(A)");
}

struct node * place(struct ffblk ff,struct node *first,int don)
{
 static int j;
 void create(struct node *first,char *ch,int d);
 void insert(struct node *first,char *ch,int d);
 int i=0,c=0;
 char *p;
 if(don!=0)
  first=NULL;
 else
 {
 while(don==0)
 {
  if(i==0)
  {
   first=(struct node *)malloc(sizeof(struct node));
   if ((p = (char *) malloc(14)) == NULL)
    exit(1);
   strcpy(p,ff.ff_name);
   create(first,p,ff.ff_attrib);
   i=1;
  }
  else
  {
   if ((p = (char *) malloc(14)) == NULL)
    exit(1);
   strcpy(p,ff.ff_name);
   insert(first,p,ff.ff_attrib);
  }
  don=findnext(&ff);
  c=c+1;
 }
 }
 if(j==0)
 {
 printf("*************************************************");
 printf("		 %d FILES & FOLDERS",c);
 j+=1;
 }
 else
 printf("		 %d FILES",c);
 return(first);
}

void create(struct node *first,char *ch,int d)
{
 char *p;
 if ((p = (char *) malloc(sizeof(ch))) == NULL)
  exit(1);
 p=ch;
 first-&gt;name=p;
 first-&gt;attrib=d;
 first-&gt;next=NULL;
 return;
}

void insert(struct node *first,char *ch,int d)
{
 struct node *temp,*list;
 char *p;
 list=first;
 while(list-&gt;next!=NULL)
  list=list-&gt;next;
 if ((p = (char *)malloc(sizeof(ch))) == NULL)
  exit(1);
 p=ch;
 temp=(struct node *)malloc(sizeof(struct node));
 temp-&gt;name=p;
 temp-&gt;attrib=d;
 temp-&gt;next=NULL;
 list-&gt;next=temp;
 return;
}

void display(struct node *first)
{
 struct node *list;
 void property(struct node *list);
 list=first;
 if(list==NULL)
  printf("NULL");
 else
 {
 while(list-&gt;next!=NULL)
 {
  property(list);
  printf("%s %d",list-&gt;name,list-&gt;attrib);
  list=list-&gt;next;
 }
  property(list);
  printf("%s %d",list-&gt;name,list-&gt;attrib);
 }
 return;
}

推荐答案

它不是C ++!如果是这样,您将创建一个节点类并将所有方法放在那里.这甚至是不合理的C.您正在main中尝试做太多事情.将此函数的主体保留为仅一行,例如"TreeTest().Run()".

啊,我知道发生了什么事.您正在尝试将诸如"void display(struct node *first);"之类的函数声明放入函数内部……我不知道该怎么建议……但肯定不再解决此问题.将其列出并从头开始 ,阅读一些C ++或C手册.首先学习基本知识,做简单的非常简单的练习.您还没有准备好编写问题的代码.嘿,成千上万的人克服了这些问题;您可以做到,同样,只改变您的方法,不要着急.

我同意Richard MacCutchan的意见,并建议您现在不要在CodeProject上再提出任何问题.您的问题对您没有帮助.首先,对基本知识有所信心.

—SA
It is not C++! If it was, you would create a node class and put all methods there. This is not even reasonable C. You are trying to do too much in main. Keep the body of this function to just one line like "TreeTest().Run()".

Ah, I see what''s going on. You are trying to put function declarations like "void display(struct node *first); inside function… I don''t know what to advise… but certainly not working at this problem anymore. Set it out and start from the very beginning, read some C++ or C manual. Learn elementary things first, do simple, very simple exercises. You are not ready to code your problem yet. And hey, millions overcame those problems; you can do it, too, only change your approach and don''t rush it.

And I agree with Richard MacCutchan and would advise you to stop asking further questions at CodeProject for now. Your questions don''t help you. First, get some confidence in the very basics.

—SA


这篇关于有人可以帮我解决这个问题吗?有错误,但我对此有些困惑.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆