前田稔(Maeda Minoru)の超初心者のプログラム入門
public: : char* NextItem(char *buf); char* NextP(char *buf); char* SetInt(int tbl[], char *buf, int n); char* SetFloat(float tbl[], char *buf, int n); |
// 次の item(, か \n の次) にポイントする char* TextClass::NextItem(char *buf) { char *p; for(p=buf; *p && *p!=',' && *p!='\n'; p++); p++; return p; } |
// item の先頭「- + 数字」をポイントする char* TextClass::NextP(char *buf) { char *p; for(p=buf; *p!='-' && *p!='+' && (*p<'0'||*p>'9'); p++); return p; } |
// TEXT データを BIN に変換する char* TextClass::SetInt(int tbl[], char *buf, int n) { char *p; int cnt; cnt= 0; p= buf; while(cnt<n) { p= NextP(p); tbl[cnt]= atoi(p); cnt++; p= NextItem(p); } return(p); } |
// TEXT データを FLOAT に変換する char* TextClass::SetFloat(float tbl[], char *buf, int n) { char *p; int cnt; cnt= 0; p= buf; while(cnt<n) { p= NextP(p); tbl[cnt]= (float)atof(p); cnt++; p= NextItem(p); } return(p); } |
111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 99, 98, 97, 96, 95, 5, 4, 3, 2, 1, 12.1, 12.2, 12.3, 12.4, 12.5 3.14, 3.15, 3.16, 3.17, 3.18, |
int T_int[50]; float T_float[20]; |