長いCファイル内に構造体ブロックがあります
struct node {
int val;
struct node *next;
};
sed 関数を使用してこの構造体ブロックを見つけて 1 行に変換するにはどうすればよいですか。したがって、次のようになります。
struct node { int val; struct node *next;};
前もって感謝します
私の入力はこれです:
struct node {
int val;
struct node *next;
};
typedef struct {
int numer;
int denom;
} Rational;
int main()
{
struct node head;
Rational half, *newf = malloc(sizeof(Rational));
head = (struct node){ 5, NULL };
half = (Rational){ 1, 2 };
*newf = (Rational){ 2, 3 };
}
私の出力は次のとおりです。
struct node { int val; struct node *next;};
typedef struct { int numer; int denom;} Rational;int main(){struct node head;Rational half, *newf = malloc(sizeof(Rational));head = (struct node){ 5, NULL };
half = (Rational){ 1, 2 };
*newf = (Rational){ 2, 3 };
}
struct node { int val; struct node *next;};
struct node:と typedef struct:typedef struct { int numer; int denom;} Rational;
を 1 行にまとめたいだけです。ただし、int main() は Rational の末尾に追加されています。
メイン関数の内容はそのまま残してほしい。