void FreePlayGround::create(row_col size) { setPlayGroundSize(size); setContentSize(Size((baseMeasureMent + baseSplit) * size.row + baseSplit, (baseMeasureMent + baseSplit) * size.col + baseSplit)); Size contentSize = getContentSize(); auto layer = LayerColor::create(Color4B::WHITE, contentSize.width, contentSize.height); layer->setOpacity(40); this->addChild(layer, 10, maskTag); for (short i = 0; i != size.row; ++i) { for (short j = 0; j != size.col; ++j) { auto base = Sprite::create("base.png"); base->setColor(Color3B(238, 238, 238)); base->setOpacity(100); base->setPosition(Vec2(baseSplit * (i + 1) + baseMeasureMent * (i + 0.5), baseSplit * (j + 1) + baseMeasureMent * (j + 0.5))); this->addChild(base); row_col info = {i, j}; insertDict(base, info); } } }
//main fuction that initilizes trie, receives user input, and runs the autocomplete function int main(void){ TrieNode *trie=initTrie(); char word[buffer]; insertDict(trie); while(1){ printf("Enter a word to autocomplete\n"); //reads user input into word unless CTRL-D is entered which will send EOF to fgets resulting in NULL therefore ending program if(fgets(word,buffer,stdin)== NULL) break; size_t length = strlen(word) - 1; if (word[length] == '\n') //replaces troublesome /n from fgets with more appropriate /0 to indicate word end word[length] = '\0'; autocomplete(trie,word); } }
int loadIndex(const char *filename){ FILE *fp; int max_file_id=0; if((fp=fopen(filename, "r")) == NULL) { printf("%s\n", "open file error"); } else { for(;;) { char word[100]; int count; if(feof(fp)) break; if(fscanf(fp, "%s",word)!=1) break; fscanf(fp, "%d ",&count); //printf("%s\n", word); for(int i=0;i<count;i++){ int file_id=0; int each_count; fscanf(fp, "%d",&file_id); fscanf(fp, "%d",&each_count); max_file_id=max(max_file_id,file_id); for(int j=0;j<each_count;j++) insertDict(word,file_id); } } fclose(fp); } return max_file_id; }