?? source.c
字號(hào):
#include "source.h"Source::Source( char delim[], char *fn){ if(fn== NULL) { fname = new char[1024];// printf("Please enter training file name:"); scanf("%s", fname);#ifdef BDG cout << fname <<endl;#endif } else { fname = new char[strlen(fn)+1]; strcpy(fname, fn); } handle = fopen(fname, "r"); ERROR2(handle, "File %s cannot be opened!", fname); strcpy(delimiter, delim); n_Instances = countInstances(); n_Descriptions = countDescriptions(); buffer = NULL;}void Source::init(){ fseek (handle, 0L, SEEK_SET);}Description Source::readDescription(){ if(buffer==NULL) { where = buffer = new char[MAXLEN]; fgets(buffer, 2048, handle); } if(where == NULL) { fgets(buffer, 2048, handle); where = buffer; } if(where) { char *curr = where; where = strstr(where,delimiter); if(where) *where = 0;// cout << curr<<(where!=NULL)?(*where):""; Description val = atof(curr);// cout << val <<"\n"; if(where) where++; // to next value return val; }}int Source::countInstances(){ n_Instances = 0; char tmp[MAXLEN]; long int pos = ftell(handle); init(); while(!feof(handle)) { if(fgets(tmp, MAXLEN, handle) != NULL) n_Instances++; } fseek (handle, pos, SEEK_SET);// n_Instances --;// cout << "Instance :"<<n_Instances; return n_Instances;}int Source::countDescriptions(){ n_Descriptions = 0; char tmp[MAXLEN]; long int pos = ftell(handle); init(); if(fgets(tmp, MAXLEN, handle) != NULL) { n_Descriptions++; char *pstr = tmp; while((pstr = strstr(pstr, delimiter)) != NULL) { pstr++; n_Descriptions++; } } fseek (handle, pos, SEEK_SET);#ifdef DBG2 cout << "Source::countDescriptions: "<<n_Descriptions<<endl;#endif return n_Descriptions;}Description *Source::readOneInstance(){ char tmp[MAXLEN]; Description *oneInst; oneInst = new Description [n_Descriptions+1]; for(int i=0; i<n_Descriptions; i++) { oneInst[i] = readDescription();#ifdef DBG2 cout << oneInst[i] <<",";#endif }#ifdef DBG2 cout <<endl;#endif return oneInst;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -