我有这样的输入文件:
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
我需要从“The Branch PC is ********
”行获取分支PC的信息,以及是否从“The Branch is Taken/Not Taken
”行获取未采取的分支。并将这两个信息存储到所有分支的二维数组中。
我在使用fopen
后感到疑惑,如何检查每一行以获取我想要的信息。
答案 0 :(得分:0)
您可以读取直到检测到行终止符,如\ r \ n或\ n,具体取决于Windows与Linux。然后在每行中读取n个字符到行终止符。
答案 1 :(得分: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);
解析后存储到数组应该不是问题..
答案 2 :(得分:0)
我怀疑如果使用一些bash脚本来执行文本文件的预处理,然后让C程序在脚本的输出上工作,那将会容易得多