文字列の分割
Posted: 2009年3月27日(金) 12:04
ファイルを読み込んで、"="で分割した値(内容)を取得したいのですが、
うまくうごきません。
ファイルの中身は
aaa=123
bbb=456
:
のようになっています。
うまくうごきません。
ファイルの中身は
aaa=123
bbb=456
:
のようになっています。
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ int i_idx; FILE *kp_fp_db; char ch_file[100]; char *cp_t; char *cp_info[2]; kp_fp_db = fopen("info.txt", "r"); if ( kp_fp_db == NULL ){ return 1; } while( fgets(ch_file,100,kp_fp_db) != NULL ){ cp_t = strtok(ch_file, "="); while( cp_t != NULL ){ cp_info[i_idx] = cp_t; cp_t = strtok(NULL,"="); i_idx++; } printf("***%s %s\n",cp_info[0],cp_info[1]); return 0; } }