お世話になっています。
C言語でLinuxのgrepコマンドを使えるプログラムを作っています。
塩基配列を検索しているので今のプログラムだと検索対象文字を含んだ全ての文字列を検索しています。
###発生している問題・エラーメッセージ
検索文字列 : H2' ATOM 29 H2' G5 1 -12.058 51.206 46.518 1.00 0.00 H ATOM 31 HO2' G5 1 -13.525 52.569 45.355 1.00 0.00 H ATOM 63 H2' G 2 -5.805 51.267 44.087 1.00 0.00 H ATOM 65 HO2' G 2 -5.185 53.487 44.583 1.00 0.00 H ATOM 96 H2' A 3 -1.401 50.499 40.822 1.00 0.00 H ATOM 98 HO2' A 3 0.184 52.202 41.255 1.00 0.00 H ATOM 130 H2' G 4 0.806 46.863 37.050 1.00 0.00 H ATOM 132 HO2' G 4 3.013 47.988 37.547 1.00 0.00 H ATOM 164 H2' G 5 -0.550 44.397 32.752 1.00 0.00 H ATOM 166 HO2' G 5 1.286 42.680 32.880 1.00 0.00 H
エラーメッセージ
test6.c: In function ‘main’:
test6.c:21: error: too few arguments to function ‘match_str_column’
###C言語
#include<stdio.h> #include<string.h> int match_str_column(const char *a, const char *b, int column); int main (void) { FILE *fp; int chk; char a[100000],fname[256],sstr[100]; printf("検索されるファイル名 : "); scanf("%s",fname); printf("検索文字列 : "); scanf("%s",sstr); if( (fp=fopen(fname,"r"))==NULL){ printf("ファイル %s が見つかりません\n",fname);return 0; } while(fgets(a,1000,fp)!=NULL){ chk = match_str_column(a, sstr,3); if (chk==1){ printf("%s\n",a); } } return 0; } int match_str_column(const char *a, const char *b, int column) { char buf[1000]; char *str; char *tok; int count = 3; strcpy(buf, a); tok = strtok(buf, " \t\r\n"); if(tok == NULL) return 0; while(tok != NULL) { str = tok; if(++count == column) break; tok = strtok(NULL, " \t\r\n"); } return (strcmp(str, b) == 0) ? 1 : 0;
###前提・実現したいこと
実現してもらいたいのは一番右の列の検索でその文字だけ含んだプログラミングがほしいです。
例
Hを検索したら
ATOM 164 H2' G 5 -0.550 44.397 32.752 1.00 0.00 H ATOM 166 HO2' G 5 1.286 42.680 32.880 1.00 0.00 H
とそれのみが検索されるプログラムをお願いいたします。
上のプログラムよりもよいものがある場合でもご教授頂けると幸いです。

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/30 05:01
2016/06/30 09:35
2016/06/30 09:57
2016/06/30 10:01
2016/06/30 10:11
2016/07/01 03:21
2016/07/01 03:33
2016/07/01 05:44
2016/07/01 05:54
2016/07/01 05:59
2016/07/01 06:14
2016/07/01 06:29
2016/07/01 06:38
2016/07/01 06:46
2016/07/01 06:58