gpt4 book ai didi

c - 从输入文件中读取,检查其中一些信息并将其存储在 C 中的数组中

转载 作者:行者123 更新时间:2023-11-30 20:41:34 27 4
gpt4 key购买 nike

我有这样的输入文件:

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”行获取该分支是否为Taken或Not Taken。并将这两个信息存储到所有分支的二维数组中。

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

最佳答案

我猜你想要这样的东西:

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);

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

关于c - 从输入文件中读取,检查其中一些信息并将其存储在 C 中的数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13213368/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com