teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

4

「#include <stdlib.h>」が未使用であった為、除去

2021/09/06 03:53

投稿

cx20
cx20

スコア4700

answer CHANGED
@@ -55,7 +55,6 @@
55
55
  ```c
56
56
  // read_file.c
57
57
  #include <stdio.h>
58
- #include <stdlib.h>
59
58
  #include "test.h"
60
59
 
61
60
  void read_file(char *filename, Data *df, int *n) {
@@ -103,7 +102,6 @@
103
102
  ```c
104
103
  // main.c
105
104
  #include <stdio.h>
106
- #include <stdlib.h>
107
105
  #include "test.h"
108
106
 
109
107
  #define N 100

3

「#define N 100」の場所を「test.h」→「main.c」に変更

2021/09/06 03:53

投稿

cx20
cx20

スコア4700

answer CHANGED
@@ -7,9 +7,6 @@
7
7
  #ifndef TEST_H
8
8
  #define TEST_H
9
9
 
10
- // マクロ定義
11
- #define N 100
12
-
13
10
  // 型定義
14
11
  typedef struct data {
15
12
  char student_no[128];
@@ -109,6 +106,8 @@
109
106
  #include <stdlib.h>
110
107
  #include "test.h"
111
108
 
109
+ #define N 100
110
+
112
111
  int main(void) {
113
112
  int n;
114
113
  Data score_data[N];

2

参考URLをリンクさせるよう変更

2021/09/06 03:05

投稿

cx20
cx20

スコア4700

answer CHANGED
@@ -125,8 +125,8 @@
125
125
 
126
126
  <参考>
127
127
  ■ C言語 ヘッダファイルの書き方
128
- https://monozukuri-c.com/langc-headerfile/
128
+ [https://monozukuri-c.com/langc-headerfile/](https://monozukuri-c.com/langc-headerfile/)
129
129
  ■ 最小限の分割 - 苦しんで覚えるC言語
130
- https://9cguide.appspot.com/20-01.html
130
+ [https://9cguide.appspot.com/20-01.html](https://9cguide.appspot.com/20-01.html)
131
131
  ■ インクルードガード
132
- http://www.02.246.ne.jp/~torutk/cxx/file/includeguard.html
132
+ [http://www.02.246.ne.jp/~torutk/cxx/file/includeguard.html](http://www.02.246.ne.jp/~torutk/cxx/file/includeguard.html)

1

ヘッダファイルにインクルードガード(多重インクルード防止)の記述を追加しました。

2021/09/05 16:46

投稿

cx20
cx20

スコア4700

answer CHANGED
@@ -2,8 +2,15 @@
2
2
 
3
3
  ```h
4
4
  // test.h
5
+
6
+ // 多重インクルード防止
7
+ #ifndef TEST_H
8
+ #define TEST_H
9
+
10
+ // マクロ定義
5
11
  #define N 100
6
12
 
13
+ // 型定義
7
14
  typedef struct data {
8
15
  char student_no[128];
9
16
  int score_japanese;
@@ -13,11 +20,13 @@
13
20
  int score_sum;
14
21
  } Data;
15
22
 
23
+ // プロトタイプ宣言
16
24
  void swap_Data(Data *x, Data *y);
17
25
  void bubble_sort(Data *df, int n);
18
26
  void read_file(char *filename, Data *df, int *n);
19
27
  void show_result(Data *df, int n);
20
28
 
29
+ #endif
21
30
  ```
22
31
 
23
32
  ```c
@@ -112,4 +121,12 @@
112
121
 
113
122
  return 0;
114
123
  }
115
- ```
124
+ ```
125
+
126
+ <参考>
127
+ ■ C言語 ヘッダファイルの書き方
128
+ https://monozukuri-c.com/langc-headerfile/
129
+ ■ 最小限の分割 - 苦しんで覚えるC言語
130
+ https://9cguide.appspot.com/20-01.html
131
+ ■ インクルードガード
132
+ http://www.02.246.ne.jp/~torutk/cxx/file/includeguard.html