免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4654 | 回复: 2
打印 上一主题 下一主题

[SCO UNIX] linux编程 -- 得到.c类型的文件名并在shell中使用ls命令显示出来????????? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-03-20 10:51 |只看该作者 |倒序浏览
各位大哥,我想得到.c类型的文件名并在shell中使用ls命令显示出来,以下是源代码,但是在system系统调用时system("ls name");这里的name和if(strstr(name,".c") !=0 ||strstr(name,".C")){中的name 参数怎么对应呀,我该怎么办???

#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
                                                                                                               
int main()
{
        static  DIR  *dir;
        struct   dirent   *entry;
        char *name ,i;
        if(!dir)   {
                dir = opendir("/home/zhou/src");
                if(!dir)
                        printf("Can't   open   /proc");
        }
        for(i=0;i<50;i++){
                if((entry = readdir(dir)) == NULL)   {
                        closedir(dir);
                        dir = 0;
                        return 0;
                }
                name=entry->d_name;
                if(strstr(name,".c") !=0 ||strstr(name,".C")){
//                      printf(name);
                        system("ls name");
//                      system("sleep 3");
                }
        }
}

论坛徽章:
0
2 [报告]
发表于 2007-03-20 10:53 |只看该作者

哪位大哥知道请指教,新手呀!!!!!!

哪位大哥知道请指教,新手呀!!!!!!!!!

论坛徽章:
0
3 [报告]
发表于 2007-03-26 17:24 |只看该作者
将name 打印到一个字符串里,然后接在ls后面:
string ssss;
sprintf(ssss,"ls %s",name);
system(ssss);
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP