-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 ********" から分岐が未取得または取得されているかどうかを取得する必要がありThe Branch is Taken/Not Takenます。そして、この 2 つの情報をすべてのブランチの 2 次元配列に格納します。

fopenを使用した後、各行をチェックして必要な情報を取得するにはどうすればよいか疑問に思っていました。

4

3 に答える 3

0

Windows と Linux に応じて \r\n や \n のように行末記号が検出されるまで読み取ることができます。次に、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 に答える