質問編集履歴

1

プログラムの変更

2018/07/08 16:15

投稿

forza
forza

スコア21

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- C言語 C++ でファイル操作を行い多次元配列を並び替えたいのですが下記では上手くいきません。
1
+ C言語 C++ でファイル操作を行い多次元配列を並び替えたいのですが下記ではコンパイルは通りますが上手くいきません。
2
2
 
3
3
  どのように改善すれば良いのかを教えて頂けると助かります。
4
4
 
@@ -8,31 +8,7 @@
8
8
 
9
9
 
10
10
 
11
- 現状、
12
-
13
- prog0210.c: In function ‘main’:
14
-
15
- prog0210.c:29:11: warning: assignment makes integer from pointer without a cast [enabled by default]
16
-
17
- tmp=number[j];
18
-
19
- ^
20
-
21
- prog0210.c:30:17: error: incompatible types when assigning to type ‘int[4]’ from type ‘int *’
22
-
23
- number[j]=number[k];
24
-
25
- ^
26
-
27
- prog0210.c:31:17: error: incompatible types when assigning to type ‘int[4]’ from type ‘int’
28
-
29
- number[k]=tmp;
30
-
31
-
32
-
33
- といったエラーが出ています。
34
-
35
- 宜しくお願いします。
11
+ 宜しくお願いします。
36
12
 
37
13
 
38
14
 
@@ -50,67 +26,67 @@
50
26
 
51
27
  int tmp;
52
28
 
53
- int i, j,k;
29
+ int i, j;
54
30
 
55
31
 
56
32
 
57
- FILE *fin, *fout;
33
+ FILE *fin, *fout;
58
34
 
59
35
 
60
36
 
61
- if ((fin = fopen("data2.txt", "r")) == NULL)
37
+ if ((fin = fopen("data2", "r")) == NULL)
62
38
 
63
- {
39
+ {
64
40
 
65
41
  printf("入力ファイルがありません\n");
66
42
 
67
43
  exit(1);
68
44
 
69
- }
45
+ }
70
46
 
71
- if ((fout = fopen("data4.txt", "w")) == NULL)
47
+ if ((fout = fopen("data4", "w")) == NULL)
72
48
 
73
- {
49
+ {
74
50
 
75
51
  printf("出力ファイルがありません\n");
76
52
 
77
53
  exit(1);
78
54
 
79
- }
55
+ }
80
56
 
81
57
  for (i = 0; i<7; i++)
82
58
 
83
- {
59
+ {
84
60
 
85
61
  for (j = 0; j<4; j++)
86
62
 
87
- {
63
+ {
88
64
 
89
65
  fscanf(fin, "%d", &number[i][j]);
90
66
 
91
- if(number[j]>number[k])
67
+ if(number[i][j]>number[i][j+1])
92
68
 
93
- {
69
+ {
94
70
 
95
- tmp=number[j];
71
+ tmp=number[i][j];
96
72
 
97
- number[j]=number[k];
73
+ number[i][j]=number[i][j+1];
98
74
 
99
- number[k]=tmp;
75
+ number[i][j+1]=tmp;
100
76
 
101
- }
77
+ }
102
78
 
103
- fprintf(fout,"%d",number[i][j]);
79
+ fprintf(fout,"%d",number[i][j]);
104
80
 
105
- }
81
+ }
106
82
 
107
83
  fprintf(fout, "\n");
108
84
 
109
- }
85
+ }
110
86
 
111
87
  fclose(fin);
112
88
 
113
- fclose(fout);
89
+ fclose(fout);
114
90
 
115
91
 
116
92