#include "sampler.h" #include #include using std::cout; using std::cin; using std::istream; using std::ifstream; //this is more like a C style void nullTerminateWords(char * buf) { while (*buf!='\0') { if (*buf==' ') *buf='\0'; buf++; } *(buf+1)='\n'; //real end of buffer } char * getNextWord(char * buf) { while (*buf=='\0') buf++; if (*buf!='\n') return buf; else return NULL; } void sampleInput(istream& is, bool update) { Sampler sampler; //for now assume every line is at most 255 characters //but in general one must check and re-allocate //that's why C++ string is easier to code char * orig_buf = new char[257]; //256 for '\0' and 257 for '\n' added later while (true) { char * buf=orig_buf; is.getline(buf,256); if (strlen(buf)!=0) { //could be zero because end of file nullTerminateWords(buf); //read words while (buf=getNextWord(buf)) { char * word=new char[strlen(buf)+1]; strcpy(word, buf); buf=buf+strlen(word)+1; if (!sampler.get(word)) delete[] word; } if (update) cout<