質問編集履歴
7
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -27,12 +27,12 @@
|
|
27
27
|
#include<stdio.h>
|
28
28
|
#include<string.h>
|
29
29
|
|
30
|
+
int match_str_column(const char *a, const char *b, int column);
|
30
31
|
int main (void)
|
31
32
|
{
|
32
|
-
int match_str_column(const char *a, const char *b, int column);
|
33
33
|
FILE *fp;
|
34
34
|
int chk;
|
35
|
-
char a[100000],fname[256],sstr[
|
35
|
+
char a[100000],fname[256],sstr[100];
|
36
36
|
printf("検索されるファイル名 : ");
|
37
37
|
scanf("%s",fname);
|
38
38
|
printf("検索文字列 : ");
|
@@ -44,18 +44,19 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
while(fgets(a,1000,fp)!=NULL){
|
47
|
-
chk = match_str_column(a, sstr);
|
47
|
+
chk = match_str_column(a, sstr,3);
|
48
48
|
if (chk==1){
|
49
49
|
printf("%s\n",a);
|
50
50
|
}
|
51
51
|
}
|
52
|
+
return 0;
|
52
53
|
}
|
53
54
|
int match_str_column(const char *a, const char *b, int column)
|
54
55
|
{
|
55
56
|
char buf[1000];
|
56
57
|
char *str;
|
57
58
|
char *tok;
|
58
|
-
int count =
|
59
|
+
int count = 3;
|
59
60
|
strcpy(buf, a);
|
60
61
|
tok = strtok(buf, " \t\r\n");
|
61
62
|
if(tok == NULL)
|
@@ -68,7 +69,6 @@
|
|
68
69
|
tok = strtok(NULL, " \t\r\n");
|
69
70
|
}
|
70
71
|
return (strcmp(str, b) == 0) ? 1 : 0;
|
71
|
-
}
|
72
72
|
```
|
73
73
|
|
74
74
|
###前提・実現したいこと
|
6
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,59 +18,56 @@
|
|
18
18
|
ATOM 166 HO2' G 5 1.286 42.680 32.880 1.00 0.00 H
|
19
19
|
```
|
20
20
|
エラーメッセージ
|
21
|
-
|
21
|
+
test6.c: In function ‘main’:
|
22
|
-
|
23
|
-
|
22
|
+
test6.c:21: error: too few arguments to function ‘match_str_column’
|
24
23
|
|
25
24
|
|
26
25
|
###C言語
|
27
26
|
```
|
28
27
|
#include<stdio.h>
|
29
28
|
#include<string.h>
|
30
|
-
int match_str(const char *a, const char *b);
|
31
29
|
|
32
|
-
|
30
|
+
int main (void)
|
33
31
|
{
|
32
|
+
int match_str_column(const char *a, const char *b, int column);
|
34
33
|
FILE *fp;
|
35
34
|
int chk;
|
36
|
-
char a[100000],fname[256],sstr[
|
35
|
+
char a[100000],fname[256],sstr[1000];
|
37
36
|
printf("検索されるファイル名 : ");
|
38
37
|
scanf("%s",fname);
|
39
38
|
printf("検索文字列 : ");
|
40
39
|
scanf("%s",sstr);
|
41
40
|
|
42
41
|
if( (fp=fopen(fname,"r"))==NULL){
|
43
|
-
printf("ファイル %s が見つかりません\n",fname);return;
|
42
|
+
printf("ファイル %s が見つかりません\n",fname);return 0;
|
44
43
|
}
|
45
44
|
|
46
45
|
|
47
46
|
while(fgets(a,1000,fp)!=NULL){
|
48
|
-
chk =
|
47
|
+
chk = match_str_column(a, sstr);
|
49
48
|
if (chk==1){
|
50
|
-
printf("
|
49
|
+
printf("%s\n",a);
|
51
50
|
}
|
52
51
|
}
|
53
52
|
}
|
54
|
-
|
55
|
-
int
|
53
|
+
int match_str_column(const char *a, const char *b, int column)
|
56
54
|
{
|
55
|
+
char buf[1000];
|
56
|
+
char *str;
|
57
|
+
char *tok;
|
57
|
-
int
|
58
|
+
int count = 0;
|
59
|
+
strcpy(buf, a);
|
60
|
+
tok = strtok(buf, " \t\r\n");
|
61
|
+
if(tok == NULL)
|
62
|
+
return 0;
|
58
|
-
while(
|
63
|
+
while(tok != NULL)
|
64
|
+
{
|
65
|
+
str = tok;
|
59
|
-
if(
|
66
|
+
if(++count == column)
|
60
|
-
|
67
|
+
break;
|
68
|
+
tok = strtok(NULL, " \t\r\n");
|
61
69
|
}
|
62
|
-
i=0;
|
63
|
-
while(1){
|
64
|
-
if(b[i]=='\0'){max_b = i; break;}
|
65
|
-
i++;
|
66
|
-
}
|
67
|
-
for(i=0;i<max_a;i++){
|
68
|
-
|
70
|
+
return (strcmp(str, b) == 0) ? 1 : 0;
|
69
|
-
if(j==max_b-1){return 1;}
|
70
|
-
else{j++;}
|
71
|
-
}
|
72
|
-
}
|
73
|
-
return 0;
|
74
71
|
}
|
75
72
|
```
|
76
73
|
|
5
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -82,4 +82,6 @@
|
|
82
82
|
ATOM 164 H2' G 5 -0.550 44.397 32.752 1.00 0.00 H
|
83
83
|
ATOM 166 HO2' G 5 1.286 42.680 32.880 1.00 0.00 H
|
84
84
|
```
|
85
|
-
とそれのみが検索されるプログラムをお願いいたします。
|
85
|
+
とそれのみが検索されるプログラムをお願いいたします。
|
86
|
+
|
87
|
+
上のプログラムよりもよいものがある場合でもご教授頂けると幸いです。
|
4
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -78,7 +78,8 @@
|
|
78
78
|
実現してもらいたいのは一番右の列の検索でその文字だけ含んだプログラミングがほしいです。
|
79
79
|
例
|
80
80
|
Hを検索したら
|
81
|
+
```
|
81
|
-
|
82
|
+
ATOM 164 H2' G 5 -0.550 44.397 32.752 1.00 0.00 H
|
82
83
|
ATOM 166 HO2' G 5 1.286 42.680 32.880 1.00 0.00 H
|
83
84
|
```
|
84
85
|
とそれのみが検索されるプログラムをお願いいたします。
|
3
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,13 +18,14 @@
|
|
18
18
|
ATOM 166 HO2' G 5 1.286 42.680 32.880 1.00 0.00 H
|
19
19
|
```
|
20
20
|
エラーメッセージ
|
21
|
-
|
21
|
+
上のようにHO2'もでてきてしまいます。
|
22
22
|
|
23
23
|
他にもここで一番右の列のOを検索すると全ての行のATOMが検索されてしまいます。
|
24
24
|
|
25
25
|
|
26
26
|
###C言語
|
27
|
+
```
|
27
|
-
|
28
|
+
#include<stdio.h>
|
28
29
|
#include<string.h>
|
29
30
|
int match_str(const char *a, const char *b);
|
30
31
|
|
@@ -79,4 +80,5 @@
|
|
79
80
|
Hを検索したら
|
80
81
|
```ATOM 164 H2' G 5 -0.550 44.397 32.752 1.00 0.00 H
|
81
82
|
ATOM 166 HO2' G 5 1.286 42.680 32.880 1.00 0.00 H
|
83
|
+
```
|
82
|
-
とそれのみが検索されるプログラムをお願いいたします。
|
84
|
+
とそれのみが検索されるプログラムをお願いいたします。
|
2
文法
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
###発生している問題・エラーメッセージ
|
7
|
-
検索されるファイル名 : a.pdb
|
7
|
+
```検索されるファイル名 : a.pdb
|
8
8
|
検索文字列 : H2'
|
9
9
|
ATOM 29 H2' G5 1 -12.058 51.206 46.518 1.00 0.00 H
|
10
10
|
ATOM 31 HO2' G5 1 -13.525 52.569 45.355 1.00 0.00 H
|
@@ -16,6 +16,7 @@
|
|
16
16
|
ATOM 132 HO2' G 4 3.013 47.988 37.547 1.00 0.00 H
|
17
17
|
ATOM 164 H2' G 5 -0.550 44.397 32.752 1.00 0.00 H
|
18
18
|
ATOM 166 HO2' G 5 1.286 42.680 32.880 1.00 0.00 H
|
19
|
+
```
|
19
20
|
エラーメッセージ
|
20
21
|
```上のようにHO2'もでてきてしまいます。
|
21
22
|
|
@@ -23,7 +24,7 @@
|
|
23
24
|
|
24
25
|
|
25
26
|
###C言語
|
26
|
-
#include<stdio.h>
|
27
|
+
```#include<stdio.h>
|
27
28
|
#include<string.h>
|
28
29
|
int match_str(const char *a, const char *b);
|
29
30
|
|
@@ -70,12 +71,12 @@
|
|
70
71
|
}
|
71
72
|
return 0;
|
72
73
|
}
|
74
|
+
```
|
73
75
|
|
74
|
-
|
75
76
|
###前提・実現したいこと
|
76
77
|
実現してもらいたいのは一番右の列の検索でその文字だけ含んだプログラミングがほしいです。
|
77
78
|
例
|
78
79
|
Hを検索したら
|
79
|
-
ATOM 164 H2' G 5 -0.550 44.397 32.752 1.00 0.00 H
|
80
|
+
```ATOM 164 H2' G 5 -0.550 44.397 32.752 1.00 0.00 H
|
80
81
|
ATOM 166 HO2' G 5 1.286 42.680 32.880 1.00 0.00 H
|
81
|
-
とそれのみが検索されるプログラムをお願いいたします。
|
82
|
+
とそれのみが検索されるプログラムをお願いいたします。```
|
1
文法
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|