質問編集履歴

2

問題内容の追加

2021/01/17 13:02

投稿

tumayouji
tumayouji

スコア0

test CHANGED
File without changes
test CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  条件はギリシャ文字と上付き、下付き文字の変換ですなぜうまくいかないのでしょうか。
8
8
 
9
+ また、この機能を実現したいとき、どのようなコードを書けばよいのでしょうか
10
+
9
11
 
10
12
 
11
13
 
@@ -16,7 +18,7 @@
16
18
 
17
19
  ```
18
20
 
19
- \alpha x_1とコマンドラインで実行すると &alpha x<sub>1</sub>と出力してほしいが alpha x_1という出力結果になる
21
+ \alpha x_1とコマンドラインで実行すると &alpha x<sub>1</sub>と出力してほしいが alpha x_1という出力結果になる そもそもこのコードは欠陥が多い気がします
20
22
 
21
23
  ```
22
24
 

1

コードの見易さの改善、具体的な例の追加

2021/01/17 13:01

投稿

tumayouji
tumayouji

スコア0

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  ```
18
18
 
19
- 変換がうまくいか
19
+ \alpha x_1とコマンドラインで実行すると &alpha x<sub>1</sub>と出力してほしい alpha x_1とい出力結果に
20
20
 
21
21
  ```
22
22
 
@@ -42,307 +42,287 @@
42
42
 
43
43
 
44
44
 
45
-
46
-
47
- int main( int argc, char *argv[] )
48
-
49
- {
50
-
51
- if(argc>9) {
52
-
53
- printf("Illegal number of argument.\n");
54
-
55
- return(-1);
56
-
57
- }
58
-
59
- int k,a;
60
-
61
-
62
-
63
- for(k=1; k<argc; k++){
64
-
65
-
66
-
67
- get_Greek_Mathsymbol(argv[k]);
68
-
69
- get_Lgreek(argv[k]);
70
-
71
- get_Subscript(argv[k]);
72
-
73
- get_Superscript(argv[k]);
74
-
75
-
76
-
77
- }
78
-
79
-
80
-
81
- for(a=1; a<=argc; a++){
82
-
83
- printf("%s\n", argv[a]);
84
-
85
- }
86
-
87
- return 0;
88
-
89
- }
90
-
91
-
92
-
93
- void get_Greek_Mathsymbol(char *arg){
94
-
95
-
96
-
97
- char greek[][10] = {"alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", "iota", "kappa", "lambda", "mu", "nu", "xi", "pi", "rho", "sigma", "tau", "upsilon", "phi", "chi", "psi", "omega", "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma", "Upsilon", "Phi", "Psi", "Omega" "geq", "leq"};
98
-
99
-
100
-
101
- static int Cnt1 = 0;
102
-
103
- int cnt1 = 0;
104
-
105
-
106
-
107
- if(*arg == '\' )
108
-
109
- { arg++;
110
-
111
- while(*arg != '\0'){ // これをすべての文字についてループ
112
-
113
-
114
-
115
-
116
-
117
- if(*arg != greek[Cnt1][cnt1]){
118
-
119
- break;
120
-
121
- }
122
-
123
- else if((*(arg+1) == '\0') || (*(arg+1) == '_') || (*(arg+1) == '^')){
124
-
125
- *(arg-cnt1-1) = '&';
126
-
127
- if(*arg == 'q'){
128
-
129
- *arg = '\0';
130
-
131
- }
132
-
133
- }
134
-
135
-
136
-
137
- else{
138
-
139
- arg++, cnt1++;
140
-
141
- continue;
142
-
143
- }
144
-
145
-
146
-
147
- }
148
-
149
-
150
-
151
- }
152
-
153
- Cnt1++;
154
-
155
- }
156
-
157
-
158
-
159
- void get_Lgreek(char *arg){
160
-
161
-
162
-
163
- char Greek[][10] = {"Alpha", "Beta", "Gamma", "Epsilon", "Zeta", "Eta", "Iota", "Kappa", "Mu", "Nu", "Rho", "Tau", "Chi", "omicron"};
164
-
165
- static int Cnt2 = 0;
166
-
167
- int i = 0;
168
-
169
-
170
-
171
- if((*arg == Greek[Cnt2][0]) && ((*(arg+1) == '\0') || (*(arg+1) == '_') || (*(arg+1) == '^'))){
172
-
173
- *arg = '&';
174
-
175
- arg++;
176
-
177
- while(Greek[Cnt2][i] != '\0'){
178
-
179
- *arg = Greek[Cnt2][i];
180
-
181
- arg++ ,i++;
182
-
183
- }
184
-
185
- }
186
-
187
- Cnt2++;
188
-
189
- }
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
- void get_Subscript(char *arg){
208
-
209
- char rest1[10] ;
210
-
211
- int i, j, l, m;
212
-
213
- int cnt2 = 0;
214
-
215
- char subscript[][10] = {"<sub>", "</sub>"};
216
-
217
-
218
-
219
- if(*arg == '_'){
220
-
221
- arg++;
222
-
223
- for(i=0; i<=9; i++){
224
-
225
-
226
-
227
- if((*arg == '\0') || (*arg == '^')){
228
-
229
- break;
230
-
231
- }
232
-
233
- rest1[i] = *arg;
234
-
235
- arg++, cnt2++;
236
-
237
- }
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
- for(j=0; subscript[0][j] != '\0'; j++){
246
-
247
- *(arg-cnt2-1+j) = subscript[0][j];
248
-
249
- }
250
-
251
- for(l=0; l<cnt2; l++){
252
-
253
- *(arg-cnt2+4+l) = rest1[l];
254
-
255
- }
256
-
257
- for(m=0; subscript[1][m] != '\0'; m++){
258
-
259
- *(arg+4+m) = subscript[1][m];
260
-
261
- }
262
-
263
- }
264
-
265
- else{
266
-
267
- arg++;
268
-
269
- }
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
- }
278
-
279
-
280
-
281
- void get_Superscript(char *arg){
282
-
283
- char rest2[10] ;
284
-
285
- int i, j, l, m;
286
-
287
- int cnt3 = 0;
288
-
289
- char *superscript[] = {"<sup>", "</sup>"};
290
-
291
- if(*arg == '_'){
292
-
293
- arg++;
294
-
295
- for(i=0; i<=9; i++){
296
-
297
-
298
-
299
- if(*arg == '\0'){
300
-
301
- break;
302
-
303
- }
304
-
305
- rest2[i] = *arg;
306
-
307
- arg++, cnt3++;
308
-
309
- }
310
-
311
-
312
-
313
-
314
-
315
-
316
-
317
- for(j=0; superscript[0][j] != '\0'; j++){
318
-
319
- *(arg-cnt3-1+j) = superscript[0][j];
320
-
321
- }
322
-
323
- for(l=0; l<cnt3; l++){
324
-
325
- *(arg-cnt3+4+l) = rest2[l];
326
-
327
- }
328
-
329
- for(m=0; superscript[1][m] != '\0'; m++){
330
-
331
- *(arg+4+m) = superscript[1][m];
332
-
333
-
334
-
335
- }
336
-
337
- }
338
-
339
- else{
340
-
341
- arg++;
342
-
343
- }
344
-
345
- }
45
+ int main(int argc, char *argv[]) {
46
+
47
+ if (argc > 9) {
48
+
49
+ printf("Illegal number of argument.\n");
50
+
51
+ return (-1);
52
+
53
+ }
54
+
55
+ int k, a;
56
+
57
+
58
+
59
+ for (k = 1; k < argc; k++) {
60
+
61
+
62
+
63
+ get_Greek_Mathsymbol(argv[k]);
64
+
65
+ get_Lgreek(argv[k]);
66
+
67
+ get_Subscript(argv[k]);
68
+
69
+ get_Superscript(argv[k]);
70
+
71
+
72
+
73
+ }
74
+
75
+
76
+
77
+ for (a = 1; a <= argc; a++) {
78
+
79
+ printf("%s\n", argv[a]);
80
+
81
+ }
82
+
83
+ return 0;
84
+
85
+ }
86
+
87
+
88
+
89
+ void get_Greek_Mathsymbol(char *arg) {
90
+
91
+
92
+
93
+ char greek[][10] = { "alpha", "beta", "gamma", "delta", "epsilon", "zeta",
94
+
95
+ "eta", "theta", "iota", "kappa", "lambda", "mu", "nu", "xi", "pi",
96
+
97
+ "rho", "sigma", "tau", "upsilon", "phi", "chi", "psi", "omega",
98
+
99
+ "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma", "Upsilon",
100
+
101
+ "Phi", "Psi", "Omega" "geq", "leq" };
102
+
103
+
104
+
105
+ static int Cnt1 = 0;
106
+
107
+ int cnt1 = 0;
108
+
109
+
110
+
111
+ if (*arg == '\') {
112
+
113
+ arg++;
114
+
115
+ while (*arg != '\0') { // これをすべての文字についてループ
116
+
117
+
118
+
119
+ if (*arg != greek[Cnt1][cnt1]) {
120
+
121
+ break;
122
+
123
+ } else if ((*(arg + 1) == '\0') || (*(arg + 1) == '_')
124
+
125
+ || (*(arg + 1) == '^')) {
126
+
127
+ *(arg - cnt1 - 1) = '&';
128
+
129
+ if (*arg == 'q') {
130
+
131
+ *arg = '\0';
132
+
133
+ }
134
+
135
+ }
136
+
137
+
138
+
139
+ else {
140
+
141
+ arg++, cnt1++;
142
+
143
+ continue;
144
+
145
+ }
146
+
147
+
148
+
149
+ }
150
+
151
+
152
+
153
+ }
154
+
155
+ Cnt1++;
156
+
157
+ }
158
+
159
+
160
+
161
+ void get_Lgreek(char *arg) {
162
+
163
+
164
+
165
+ char Greek[][10] = { "Alpha", "Beta", "Gamma", "Epsilon", "Zeta", "Eta",
166
+
167
+ "Iota", "Kappa", "Mu", "Nu", "Rho", "Tau", "Chi", "omicron" };
168
+
169
+ static int Cnt2 = 0;
170
+
171
+ int i = 0;
172
+
173
+
174
+
175
+ if ((*arg == Greek[Cnt2][0])
176
+
177
+ && ((*(arg + 1) == '\0') || (*(arg + 1) == '_')
178
+
179
+ || (*(arg + 1) == '^'))) {
180
+
181
+ *arg = '&';
182
+
183
+ arg++;
184
+
185
+ while (Greek[Cnt2][i] != '\0') {
186
+
187
+ *arg = Greek[Cnt2][i];
188
+
189
+ arg++, i++;
190
+
191
+ }
192
+
193
+ }
194
+
195
+ Cnt2++;
196
+
197
+ }
198
+
199
+
200
+
201
+ void get_Subscript(char *arg) {
202
+
203
+ char rest1[10];
204
+
205
+ int i, j, l, m;
206
+
207
+ int cnt2 = 0;
208
+
209
+ char subscript[][10] = { "<sub>", "</sub>" };
210
+
211
+
212
+
213
+ if (*arg == '_') {
214
+
215
+ arg++;
216
+
217
+ for (i = 0; i <= 9; i++) {
218
+
219
+
220
+
221
+ if ((*arg == '\0') || (*arg == '^')) {
222
+
223
+ break;
224
+
225
+ }
226
+
227
+ rest1[i] = *arg;
228
+
229
+ arg++, cnt2++;
230
+
231
+ }
232
+
233
+
234
+
235
+ for (j = 0; subscript[0][j] != '\0'; j++) {
236
+
237
+ *(arg - cnt2 - 1 + j) = subscript[0][j];
238
+
239
+ }
240
+
241
+ for (l = 0; l < cnt2; l++) {
242
+
243
+ *(arg - cnt2 + 4 + l) = rest1[l];
244
+
245
+ }
246
+
247
+ for (m = 0; subscript[1][m] != '\0'; m++) {
248
+
249
+ *(arg + 4 + m) = subscript[1][m];
250
+
251
+ }
252
+
253
+ } else {
254
+
255
+ arg++;
256
+
257
+ }
258
+
259
+
260
+
261
+ }
262
+
263
+
264
+
265
+ void get_Superscript(char *arg) {
266
+
267
+ char rest2[10];
268
+
269
+ int i, j, l, m;
270
+
271
+ int cnt3 = 0;
272
+
273
+ char *superscript[] = { "<sup>", "</sup>" };
274
+
275
+ if (*arg == '_') {
276
+
277
+ arg++;
278
+
279
+ for (i = 0; i <= 9; i++) {
280
+
281
+
282
+
283
+ if (*arg == '\0') {
284
+
285
+ break;
286
+
287
+ }
288
+
289
+ rest2[i] = *arg;
290
+
291
+ arg++, cnt3++;
292
+
293
+ }
294
+
295
+
296
+
297
+ for (j = 0; superscript[0][j] != '\0'; j++) {
298
+
299
+ *(arg - cnt3 - 1 + j) = superscript[0][j];
300
+
301
+ }
302
+
303
+ for (l = 0; l < cnt3; l++) {
304
+
305
+ *(arg - cnt3 + 4 + l) = rest2[l];
306
+
307
+ }
308
+
309
+ for (m = 0; superscript[1][m] != '\0'; m++) {
310
+
311
+ *(arg + 4 + m) = superscript[1][m];
312
+
313
+
314
+
315
+ }
316
+
317
+ } else {
318
+
319
+ arg++;
320
+
321
+ }
322
+
323
+ }
324
+
325
+
346
326
 
347
327
  ```
348
328