|
共有四个问题:关于kdevelop 关于输出内容(dir_demo1.c dir_demo2.c) 关于输出内容(main.c
dir_demo2.c) 关于定义
共有三个文件:main.c dir_demo1.c dir_demo2.c
问题一:在kdevelop怎么把main.c等文件输入成为一个工程而不用新建工程在每一个文件中输入(我没有
找到相关命令)
问题二:为仕么dir_demo1 dir_demo2仅定义的不同导致输出的不同
问题三:dir()作为main的接口却不能输出东西,提示错误segmentation fault;
问题四:为仕么dir_demo1中我将结构变量定义在char字符定义上就会导致是么东西都不能输出而出现
segmentation fault;
输出内容(问题二)dir_demo1 segmentation fault ;
dir_demo2 当前目录的内容;(正确的);
输出内容(问题三)main.c dir.c两个文件最后输出内容为当前目录的内容最后还带了一个segmentation
fault;
输出内容(问题四)dir_demo1 输出为segmentation fault,但是如果我把char定义和structure定义倒
过来放就
想dir.c中一样他会只输出当前目录的内容最后还带了一个segmentation fault
/***************************************************************************
dir.c - description
-------------------
begin : Wed Apr 2 2003
copyright : (C) 2003 by root
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <sys/stat.h>
#include <unistd.h>
#include <ftw.h>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
int dir(char* ccdir)
{
char*cp;
//char* ppb;
char* cp1="<DIR>";
char* cp2=" ";
int d_s1,d_s2,f_s1,f_s2;//d_s1 is how many directories; d_s2 is how many bytes in
directory; f_s1 is how many files;f_s2 is how may bytes in file
//char* gcd;
DIR* apa;
struct dirent* rpr;
struct stat* sa;
struct tm* ppa;
d_s1=0;
d_s2=0;
f_s1=0;
f_s2=0;
cp=(char *)malloc(sizeof(char)*100);
//ppb=(char *)malloc(sizeof(char)*100);
//gcd=get_current_dir_name();
//printf("%s",ccdir)
if((apa=opendir(ccdir))==NULL)
{
printf("can't print directory name\n");
}
while((rpr=readdir(apa))!=NULL)
{
stat(rpr->d_name,sa);
if((sa->st_mode)==16877)
{
//cp="<DIR>";
strcpy(cp,cp1);
d_s1+=1;
d_s2+=sa->st_size;
}
else
{
//cp=" ";
strcpy(cp,cp2);
f_s1+=1;
f_s2+=sa->st_size;
}
ppa=localtime(&(sa->st_mtime));
//ppb=ctime(&(sa->st_mtime));
printf("%d-%d-%d
%d:%d",(1900+ppa->tm_year),(1+ppa->tm_mon),ppa->tm_mday,ppa->tm_hour,ppa->tm_min);
printf("%d %s %s\n",sa->st_size,cp,rpr->d_name);
}
printf("Total Directories:%d direcories Total bytes:%d bytes\n",d_s1,d_s2);
printf("Total Files:%d files Total bytes:%d bytes\n",f_s1,f_s2);
closedir(apa);
free(cp);
//free(ppa);
//free(ppb);
return 0;
} |
|