回答編集履歴
2
列位置指定版追記
answer
CHANGED
@@ -19,4 +19,29 @@
|
|
19
19
|
return (strcmp(str, b) == 0) ? 1 : 0;
|
20
20
|
}
|
21
21
|
```
|
22
|
-
`strtok`関数は文字列を区切り文字で切り出したいときによく使います。
|
22
|
+
`strtok`関数は文字列を区切り文字で切り出したいときによく使います。
|
23
|
+
|
24
|
+
---
|
25
|
+
列位置指定番です。
|
26
|
+
columnには一番左を1とした列位置を渡します。
|
27
|
+
```C
|
28
|
+
int match_str_column(const char *a, const char *b, int column)
|
29
|
+
{
|
30
|
+
char buf[1000];
|
31
|
+
char *str;
|
32
|
+
char *tok;
|
33
|
+
int count = 0; // 列位置カウント用
|
34
|
+
strcpy(buf, a);
|
35
|
+
tok = strtok(buf, " \t\r\n");
|
36
|
+
if(tok == NULL)
|
37
|
+
return 0;
|
38
|
+
while(tok != NULL)
|
39
|
+
{
|
40
|
+
str = tok;
|
41
|
+
if(++count == column) // 指定した列位置を取り出したら
|
42
|
+
break; // ループを抜ける
|
43
|
+
tok = strtok(NULL, " \t\r\n");
|
44
|
+
}
|
45
|
+
return (strcmp(str, b) == 0) ? 1 : 0;
|
46
|
+
}
|
47
|
+
```
|
1
行内に有効な文字列がない場合のチェックを追加
answer
CHANGED
@@ -9,6 +9,8 @@
|
|
9
9
|
char *tok;
|
10
10
|
strcpy(buf, a);
|
11
11
|
tok = strtok(buf, " \t\r\n");
|
12
|
+
if(tok == NULL)
|
13
|
+
return 0;
|
12
14
|
while(tok != NULL)
|
13
15
|
{
|
14
16
|
str = tok;
|