3

入力ファイルから、次のようなテキストがあります。

func:
    sll  $t3, $t4, 5       # t1 = (i * 4)
    add  $t3, $a1, $t4     # t2 contains address of array[i]
    sw   $t1, 4($t2)       # array[i] = i
    addi $t2, $t5, 3       # i = i+1

それを「クリーン」にして、次のような別のファイルに出力したいと思います。

func:
    sll  $t3, $t4, 5
    add  $t3, $a1, $t4
    sw   $t1, 4($t2)
    addi $t2, $t5, 3

これを行うために使用しているコードブロックは次のとおりです。

    while(fgets(line, 100, input) != NULL)
   {
    int comment = 0;
    for(int x = 0; x < 100; x++)
    {
        if(line[x] == '#')
            comment = 1;

        if(comment == 1)
            line[x] = '\0'; //I know this is incorrect
    }
    fprintf(cleaned, "%s", line);
   }

そのコード ブロックを変更して、希望どおりに動作させるにはどうすればよいですか? '\n' '\0' と " " をいじっていくつか試してみましたが、どれもうまくいきませんでした。

前もって感謝します!

4

3 に答える 3