-2

我有这样的输入文件:

The Branch PC is e05f56f8

The Branch Type is branch_type_1

The Branch is Taken

The Branch Target is e045ac20

jal__        1141512 


The Branch PC is e045ac44

The Branch Type is branch_type_1

The Branch is Taken

The Branch Target is e05f57d4

jal__        1562101


The Branch PC is e05f57fc

The Branch Type is branch_type_1

The Branch is Taken

The Branch Target is e05f578c

jal__        1562083

我需要从“”行获取分支PC的信息,以及从“ The Branch PC is ********”行获取分支是否被Taken for Not Taken The Branch is Taken/Not Taken。并将这两个信息存储到所有分支的二维数组中。

我想知道使用后fopen,如何检查每一行以获得我想要的信息。

4

3 回答 3

0

您可以阅读直到检测到行终止符,如 \r\n 或 \n ,具体取决于 Windows 与 Linux。然后将 n 个字符读入每一行到行终止符。

于 2012-11-03T20:59:36.673 回答
0

我猜你想要类似的东西:

char hm[20], line[128];
FILE *fd=fopen("lol", "r");
while(fgets(line, 128, fd)) {
    if(strstr(line, "PC")) sscanf(line, "The Branch PC is %s\n", &hm);
    if(strstr(line, "Not Taken")) printf("%s Not taken !\n", hm);
    else if(strstr(line, "Taken")) printf("%s Taken !\n", hm);
}
fclose(fd);

解析后存储到数组中应该不是问题..

于 2012-11-03T21:00:32.053 回答
0

我怀疑如果您使用一些 bash 脚本来执行文本文件的预处理,然后让 C 程序处理脚本的输出,这会容易得多

于 2012-11-03T21:23:01.117 回答