/** * Plays a sound definition file (*.sdf) through PC speaker. SDF files * should reside in the gfiles dir. The only params passed to function are * filename and false if playback is unabortable, true if it is abortable. If no * extension then .SDF is appended. A full path to file may be specified to * override gfiles dir. Format of file is: * * <freq> <duration in ms> [pause_delay in ms] * 1000 1000 50 * * Returns 1 if sucessful, else returns 0. The pause_delay is optional and * is used to insert silences between tones. */ bool play_sdf(const std::string soundFileName, bool abortable) { WWIV_ASSERT(!soundFileName.empty()); std::string fullPathName; // append gfilesdir if no path specified if (soundFileName.find(WWIV_FILE_SEPERATOR_CHAR) == std::string::npos) { std::ostringstream ss; ss << syscfg.gfilesdir << soundFileName; fullPathName = ss.str(); } else { fullPathName = soundFileName; } // append .SDF if no extension specified if (fullPathName.find('.') == std::string::npos) { fullPathName += ".sdf"; } // Must Exist if (!WFile::Exists(fullPathName)) { return false; } // must be able to open read-only WTextFile soundFile(fullPathName, "rt"); if (!soundFile.IsOpen()) { return false; } // scan each line, ignore lines with words<2 std::string soundLine; while (soundFile.ReadLine(&soundLine)) { if (abortable && bkbhit()) { break; } int nw = wordcount(soundLine.c_str(), DELIMS_WHITE); if (nw >= 2) { int freq = atoi(extractword(1, soundLine, DELIMS_WHITE)); int dur = atoi(extractword(2, soundLine, DELIMS_WHITE)); // only play if freq and duration > 0 if (freq > 0 && dur > 0) { int nPauseDelay = 0; if (nw > 2) { nPauseDelay = atoi(extractword(3, soundLine, DELIMS_WHITE)); } WWIV_Sound(freq, dur); if (nPauseDelay > 0) { WWIV_Delay(nPauseDelay); } } } } soundFile.Close(); return true; }
int main() { char buf[10000];//=" hwel a dsa asd hello asdas ewqe qw helo asd nmcl kxvchj hello asdn "; char copy[sizeof(buf)]; gets(buf);//read a line strcpy(copy,buf); //rotateonlywords(buf); //printf("%s\n",buf); char ** word=NULL; int n=extractword(buf,word);//传参的时候,注意函数中word的格式,加了引用符号,不然的话word不会被改变的 printf("the number of words is : %d\n\nsorted words:\n",n); sortword(word,n); for(int i=0;i<n;i++) printf("%s\n",word[i]); //rotateallword(buf);s //printf("\n%s\n",buf); return 0; }