回答編集履歴
1
sample
test
CHANGED
@@ -11,3 +11,45 @@
|
|
11
11
|
|
12
12
|
|
13
13
|
findする関数の中で入力も受けるのは意味がわからないのでmain関数でfgetsしましょう。それが原因です
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
```c
|
18
|
+
|
19
|
+
#include <stdio.h>
|
20
|
+
|
21
|
+
#include <string.h>
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
int main(void){
|
26
|
+
|
27
|
+
char str[100];
|
28
|
+
|
29
|
+
printf("文字列を入力>>>");
|
30
|
+
|
31
|
+
fgets(str, sizeof(str) / sizeof(*str), stdin);
|
32
|
+
|
33
|
+
const char* re = strchr(str, 'a');
|
34
|
+
|
35
|
+
if(NULL == re){
|
36
|
+
|
37
|
+
puts("入力された文字列にaはありません。");
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
else{
|
42
|
+
|
43
|
+
printf("%ld文字目に最初のaがあります。\n", re - str + 1);
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
return 0;
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
実行結果: [https://wandbox.org/permlink/EffXEeMw8nysr8bP](https://wandbox.org/permlink/EffXEeMw8nysr8bP)
|