回答編集履歴

3

引数の順番syuusei

2015/11/17 11:15

投稿

catsforepaw
catsforepaw

スコア5938

test CHANGED
@@ -10,9 +10,9 @@
10
10
 
11
11
  int hour, minute;
12
12
 
13
- int count = sscanf("%c %c %d:%d", buf, &name, &io, &hour, &minute);
13
+ int count = sscanf(buf, "%c %c %d:%d", &name, &io, &hour, &minute);
14
14
 
15
- //int count = sscanf_s("%c %c %d:%d", buf, &name, 1, &io, 1, &hour, &minute); // VC++の場合
15
+ //int count = sscanf_s(buf, "%c %c %d:%d", &name, 1, &io, 1, &hour, &minute); // VC++の場合
16
16
 
17
17
  if(count != 4)
18
18
 

2

訂正漏れ

2015/11/17 11:15

投稿

catsforepaw
catsforepaw

スコア5938

test CHANGED
@@ -1,6 +1,6 @@
1
- 複数のデータが1行にまとめて入っている中から、それぞれのデータを別々に取り出すには、`scanf`関数を使うと簡単にできます。
1
+ 複数のデータが1行にまとめて入っている中から、それぞれのデータを別々に取り出すには、`sscanf`関数を使うと簡単にできます。
2
2
 
3
- ※お使いの環境が判りませんが、VC++の場合は`scanf`が使えないので`scanf_s`を使います。
3
+ ※お使いの環境が判りませんが、VC++の場合は`sscanf`が使えないので`sscanf_s`を使います。
4
4
 
5
5
  ```C
6
6
 
@@ -41,3 +41,13 @@
41
41
  ```
42
42
 
43
43
  となります。
44
+
45
+ ---
46
+
47
+ 追記
48
+
49
+
50
+
51
+ すでに読み込んだバッファから取り出す場合は`sscanf`系を使います。
52
+
53
+ `scanf`系はファイルから読み込むのですが、何かと問題があるので`sscanf`の方をご使用ください。

1

scanfではなくsscanfです。

2015/11/17 11:09

投稿

catsforepaw
catsforepaw

スコア5938

test CHANGED
@@ -10,9 +10,9 @@
10
10
 
11
11
  int hour, minute;
12
12
 
13
- int count = scanf("%c %c %d:%d", buf, &name, &io, &hour, &minute);
13
+ int count = sscanf("%c %c %d:%d", buf, &name, &io, &hour, &minute);
14
14
 
15
- //int count = scanf_s("%c %c %d:%d", buf, &name, 1, &io, 1, &hour, &minute); // VC++の場合
15
+ //int count = sscanf_s("%c %c %d:%d", buf, &name, 1, &io, 1, &hour, &minute); // VC++の場合
16
16
 
17
17
  if(count != 4)
18
18