Created
December 27, 2012 12:35
-
-
Save alphaKAI/4388055 to your computer and use it in GitHub Desktop.
stdlib.hのsystem関数の引数にmecabのコマンド投げてそれの返り値を変数に入れたいんだけど うまくうごかない・・・(自分用ライブラリ https://github.com/alphaKAI/alpha_kai_NET_my_lib 使用)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "my_lib.h" | |
int main(void){ | |
//RetrunStrings | |
char filename[]= "data.txt"; | |
char str[1000]; | |
int get_line; | |
int return_sum; | |
//main | |
int i; | |
int num; | |
int sum; | |
int dum; | |
int kum; | |
char mecab[260]; | |
char tmp[260]; | |
FILE *fp; | |
dum=check(filename); | |
if(dum==0){ | |
printf("ERROR:\n"); | |
printf("カレントディレクトリに%sがありません\n", filename); | |
printf("終了します"); | |
return 1; | |
} | |
else if(dum==1){ | |
sum=how_line(filename); | |
for(i=1; i<=sum; i++){ | |
return_sum = ReturnStrings(filename, i, str, 1000); | |
if(return_sum!=0){ | |
switch(return_sum){ | |
case -1: | |
printf("ファイルオープンに失敗\n"); | |
return -1; | |
break; | |
case -2: | |
printf("データ取得失敗\n"); | |
return -2; | |
break; | |
default: | |
printf("返り値が異常です\n"); | |
break; | |
} | |
} | |
sprintf(tmp, "echo %s | mecab -F \"%h\n\" -E \" \"", str); | |
num=system(tmp); | |
printf("num:%d\n", num); | |
sprintf(tmp, "%d.txt", num); | |
kum=check(tmp); | |
if(kum==1){ | |
fp=fopen(tmp, "ab"); | |
} | |
else if(kum==0){ | |
fp=fopen(tmp, "wt"); | |
} | |
fprintf(fp, "%s\n", str); | |
fclose(fp); | |
} | |
} | |
else{ | |
printf("ERROR:\n"); | |
printf("ファイルチェックの返り値が異常\n"); | |
return 3; | |
} | |
printf("Complete\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment