C到java文件读取和打印
我有一个C代码,它是以下输出: 输入:C到java文件读取和打印,java,c,Java,C,我有一个C代码,它是以下输出: 输入:/includeCrawler-Itest s_01.c 输出:s_01.o:s_01.ci_60.hi_44.hi_46.hi_04.hi_51.hi_15.hi_33.hi_29.hi_16.h S_01.c: #include "i_60.h" #include "i_44.h" #include "i_46.h" #include "i_04.h" #include "i_51.h" #include "i_15.h" #include <st
/includeCrawler-Itest s_01.c
输出:s_01.o:s_01.ci_60.hi_44.hi_46.hi_04.hi_51.hi_15.hi_33.hi_29.hi_16.h
S_01.c:
#include "i_60.h"
#include "i_44.h"
#include "i_46.h"
#include "i_04.h"
#include "i_51.h"
#include "i_15.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <signal.h>
i_60.c
#ifndef _I_60_H_
#define _I_60_H_
#include "i_33.h"
#include "i_04.h"
#include "i_29.h"
#include <stdio.h>
#endif /* _I_60_H_ */
好的,我假设您已经实现了一个名为readFile(stringfilename)的函数,它将返回一个它所依赖的文件名数组(或者可能是一个linkedList) 您可以使用递归过程。顺便说一句,您可以使用Set来保存文件名,而不是linkedList
// a set of filenames that have been read
HashSet<String> setOfProceededFilenames = new HashSet<String> ();
// recursively read the files
private void recursivelyReadFiles(String filename) {
// we have defined String [] readFile(String filename)
String [] dependencies = readFile(filename);
// we only read those haven't been proceeded
for (String dependentFile : dependencies) {
if (!setOfProceededFilenames.contains(dependentFile)){
// add this file to the set and read its dependencies
setOfProceededFilenames.add(dependentFile);
recursivelyReadFiles(dependentFile);
}
}
}
//已读取的一组文件名
HashSet-setofprocededFileNames=新的HashSet();
//递归地读取文件
私有void recursivelyReadFiles(字符串文件名){
//我们已定义字符串[]readFile(字符串文件名)
String[]dependencies=readFile(文件名);
//我们只看了那些还没有开始的
对于(字符串依赖文件:依赖项){
如果(!setOfProceedFileNames.contains(dependentFile)){
//将此文件添加到集合并读取其依赖项
添加(dependentFile)的过程名称集合;
递归读取文件(dependentFile);
}
}
}
谢谢您的回复,这意味着我必须保留另一个列表来保存文件名的其余部分吗?我真的不太明白你的意思meant@user3015758嗯,您实际上不需要另一个数据结构来保存尚未读取的文件名,因为它们都处于“依赖关系”中:(1)那么我如何才能将您的代码实现到当前代码中?对不起,我不太明白Hashset部分。如果你能看到我当前的代码,并可能指导我如何实现它,这可以吗?谢谢,你有skype或something@user3015758我不介意,但这是家庭作业还是什么?关于哈希映射,您可以参考oracle官方java文档,这将非常有帮助。是的。。我有一些困难,你能在2006年下午把我加入skype吗
// a set of filenames that have been read
HashSet<String> setOfProceededFilenames = new HashSet<String> ();
// recursively read the files
private void recursivelyReadFiles(String filename) {
// we have defined String [] readFile(String filename)
String [] dependencies = readFile(filename);
// we only read those haven't been proceeded
for (String dependentFile : dependencies) {
if (!setOfProceededFilenames.contains(dependentFile)){
// add this file to the set and read its dependencies
setOfProceededFilenames.add(dependentFile);
recursivelyReadFiles(dependentFile);
}
}
}