有个C程序,用来批量压缩文件夹里的文件压缩为rar格式,出了点问题

来源:百度知道 编辑:UC知道 时间:2024/07/05 14:44:06
利用rar for linux,将一个目录下所有的文件夹里的文件分别压缩为rar格式,一个文件夹对应一个rar,执行后毫无反应。
麻烦各位给看看~

#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <string.h>
char *rar="rar";
char *cpp="cpp";
char *dot=".";
char *dotdot="..";
char *allfiles="/*.* ";
int main() {
char *dir=dot;
DIR *dp;
struct dirent *entry;
struct stat statbuf;
if((dp=opendir(dir))==NULL)
{
fprintf(stderr,"cannot open directory:%s\n",dir);
return;
}
chdir(dir);
while((entry=readdir(dp))!=NULL)
{
if(strcmp(entry->d_name,dot)==0 || strcmp(entry->d_name,dotdot)==0)
continue;
char currfile[256];
char fullpath[256];
strcat(fullpath,dir);
sprintf(currfile,"%s/%s",fullpath,entry->d_name);
stat(currfil

大概看了一下,有几个疑问:
1、rar软件也在压缩文件夹里吗?因为你写的是./rar
2、system函数的参数似乎有问题,最外面的两个strcat是不是可以去掉了

我现在没有环境,你可以用gdb跟一下,很容易找到问题所在的