/** * 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; }
void main() { clrscr(); ofstream fout("poem.txt",ios::trunc); fout<<"if you are not willing to learn,\n " <<"No one can help you.\n " <<"If you are determined to learn,\n " <<"No one can stop you."; fout.close(); int x; do { cout<<"\n1-Display file\n2-lower case to upper case\n3-total character\n4-no of words\n5-Average word size\n6-no of lower case and upper case\n7-vowels\n8-no of words starting with I\n9-no. of lines ending with '.'\n10-exit\n"; cin>>x; switch(x) { case 1:display(); break; case 2:lowertoupper(); cout<<"\nFile with lower to upper\n"; display(); break; case 3:cout<<"\nNo. of characters="<<char_count(); break; case 4:cout<<"\nNo. of words="<<wordcount(); break; case 5:cout<<"\nAverage word size=" <<(float)(char_count())/(float)(wordcount()); break; case 6:lowercount_uppercount(); break; case 7:cout<<"\n\nVowels in the file are\n"; vowels(); break; case 8:cout<<"\nNo. of words starting with I=" <<counti(); break; case 9:cout<<"\nNo. of lines ending with \'.\'=" <<dotcount(); break; case 10: break; default: cout<<"Wrong input\n"; } }while(x!=10); }
int main(int argc, char *argv[]) { int count; switch(argc) { case 3: count = wordcount(argv[1], argv[2]); printf("%d\n", count); break; default: printf("Usage: %s <word> <filename>\n", argv[0]); } }
int read_xvg(char *fn,real ***y,int *ny) { FILE *fp; char *ptr; char *base=NULL; char *fmt=NULL; int k,line=0,nny,nx,maxx,rval; double lf; real **yy=NULL; *ny = 0; nny = 0; nx = 0; maxx = 0; fp = ffopen(fn,"r"); while ((ptr = fgets3(fp)) != NULL) { line++; trim(ptr); if ((ptr[0] != '@') && (ptr[0] != '#')) { if (nny == 0) { (*ny) = nny = wordcount(ptr); /* fprintf(stderr,"There are %d columns in your file\n",nny);*/ if (nny == 0) return 0; snew(yy,nny); snew(fmt,3*nny+1); snew(base,3*nny+1); } /* Allocate column space */ if (nx >= maxx) { maxx+=1024; for(k=0; (k<nny); k++) srenew(yy[k],maxx); } /* Initiate format string */ fmt[0] = '\0'; base[0] = '\0'; /* fprintf(stderr,"ptr='%s'\n",ptr);*/ for(k=0; (k<nny); k++) { strcpy(fmt,base); strcat(fmt,"%lf"); rval = sscanf(ptr,fmt,&lf); /* fprintf(stderr,"rval = %d\n",rval);*/ if ((rval == EOF) || (rval == 0)) break; yy[k][nx] = lf; srenew(fmt,3*(nny+1)+1); srenew(base,3*nny+1); strcat(base,"%*s"); } if (k != nny) { fprintf(stderr,"Only %d columns on line %d in file %s\n", k,line,fn); for( ; (k<nny); k++) yy[k][nx] = 0.0; } nx++; } } ffclose(fp); *y = yy; return nx; }
void functions (char * text[], int linesNum){ char c [80], k [80]; char * ptr = &c; int i, j = 0, l = 0, number; int white_text = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE |FOREGROUND_INTENSITY; help (linesNum); PosColor (5, 7 + linesNum, white_text); printf ("Please, enter the needed function without a number\n\n HERE>> "); gets (c); for (i = 0; i < 80; i++){ if (c[i] != ' '){ k[j] = c[i]; j++; l = 1; } if (c[i] == ' ' && l == 1){ k[j] = c[i]; j++; k[j] = 0; break; } } if (strcmp(k, "random") == 0 || strcmp(k, "shorterthan") == 0 || strcmp(k, "longerthan") == 0){ printf ("Enter the number >> "); scanf ("%i", &number); printf ("\n"); printf ("%i", number); } clearaftertable (linesNum); if (strcmp(k, "help") == 0){ help (linesNum); } else if (strcmp(k, "exit") == 0){ PosColor (0,0,0); system ("cls"); getch(); initRectf(); } else if (strcmp(k, "length") == 0){ lenofstrings (text, linesNum); } else if (strcmp(k, "longest") == 0){ maxlen (text, linesNum); } if (strcmp(k, "shortest") == 0){ minlen (text, linesNum); } if (strcmp(k, "random") == 0){ randomletters(text, linesNum, number); } if (strcmp(k, "swap") == 0){ change (text, linesNum); } if (strcmp(k, "shorterthan") == 0){ findlessthan (text, linesNum, number); } if (strcmp(k, "longerthan") == 0){ findmorethan (text, linesNum, number); } if (strcmp(k, "numberofwords") == 0){ wordcount (text, linesNum); } if (strcmp(k, "integer") == 0){ findNumInAllStrings(text, linesNum); } functions(text, linesNum); }
/* -------------------------------------------------------------------- */ int editText(char *buf, int lim) { char ch, x; FILE *fd; int eom; dowhat = PROMPT; do { outFlag = IMPERVIOUS; while (MIReady()) /* flush modem input buffer */ getMod(); doCR(); strcpy(gprompt,"Entry command:"); /* in case of ^A? */ mtPrintf(TERM_REVERSE,gprompt); mPrintf(" "); switch (ch = (char) toupper(iChar())) { case 'A': mPrintf("\bAbort\n "); if (strblank(buf)) return FALSE; else if (getYesNo(confirm, 0)) { heldMessage = TRUE; memcpy(msgBuf2, msgBuf, sizeof(struct msgB)); dowhat = DUNO; return FALSE; } break; case 'C': mPrintf("\bContinue"); /* dump message to display */ outFlag = IMPERVIOUS; doCR(); putheader(); doCR(); outFlag = OUTOK; mFormat(buf); doBS(); eom = strlen(buf); if (eom > 0) buf[eom - 1] = '\0'; /* zap last character ('\n') */ outFlag = IMPERVIOUS; return ERROR; /* to return to this routine */ case 'F': mPrintf("\bFind & Replace text\n "); replaceString(buf, lim, TRUE); break; case 'P': mPrintf("\bPrint formatted\n "); doCR(); outFlag = IMPERVIOUS; putheader(); doCR(); outFlag = OUTOK; mFormat(buf); termCap(TERM_NORMAL); doCR(); break; case 'R': mPrintf("\bReplace text\n "); replaceString(buf, lim, FALSE); break; case 'S': mPrintf("\bSave buffer\n "); entered++; /* increment # messages entered */ dowhat = DUNO; return TRUE; case 'W': mPrintf("\bWord count\n "); wordcount(buf); break; case '?': nextmenu("edit", &(cfg.cnt.edittut), 1); break; default: if ((x = (char) strpos((char) tolower(ch), editcmd)) != 0) { x--; mPrintf("\b%s", edit[x].ed_name); doCR(); if (edit[x].ed_local && !onConsole) { mPrintf("\n Local editor only!\n "); } else { changedir(cfg.aplpath); if ((fd = fopen("message.apl", "wb")) != NULL) { xPutStr(fd, msgBuf->mbtext); fclose(fd); } readMessage = FALSE; extFmtRun(edit[x].ed_cmd, "message.apl"); changedir(cfg.aplpath); if ((fd = fopen("message.apl", "rb")) != NULL) { GetStr(fd, msgBuf->mbtext, cfg.maxtext); fclose(fd); unlink("message.apl"); } } break; } if (!gl_user.expert) nextmenu("edit", &(cfg.cnt.edittut), 1); else mPrintf("\n '?' for menu.\n \n"); break; } } while (!ExitToMsdos && (haveCarrier || onConsole)); dowhat = DUNO; return FALSE; }
int read_xvg_legend(const char *fn, double ***y, int *ny, char **subtitle, char ***legend) { FILE *fp; char *ptr, *ptr0, *ptr1; char *base = NULL; char *fmt = NULL; int k, line = 0, nny, nx, maxx, rval, legend_nalloc, set, nchar; double lf; double **yy = NULL; char *tmpbuf; int len = STRLEN; *ny = 0; nny = 0; nx = 0; maxx = 0; fp = gmx_fio_fopen(fn, "r"); snew(tmpbuf, len); if (subtitle != NULL) { *subtitle = NULL; } legend_nalloc = 0; if (legend != NULL) { *legend = NULL; } while ((ptr = fgets3(fp, &tmpbuf, &len, 10*STRLEN)) != NULL && ptr[0] != '&') { line++; trim(ptr); if (ptr[0] == '@') { if (legend != NULL) { ptr++; trim(ptr); set = -1; if (strncmp(ptr, "subtitle", 8) == 0) { ptr += 8; if (subtitle != NULL) { *subtitle = read_xvgr_string(ptr); } } else if (strncmp(ptr, "legend string", 13) == 0) { ptr += 13; sscanf(ptr, "%d%n", &set, &nchar); ptr += nchar; } else if (ptr[0] == 's') { ptr++; sscanf(ptr, "%d%n", &set, &nchar); ptr += nchar; trim(ptr); if (strncmp(ptr, "legend", 6) == 0) { ptr += 6; } else { set = -1; } } if (set >= 0) { if (set >= legend_nalloc) { legend_nalloc = set + 1; srenew(*legend, legend_nalloc); (*legend)[set] = read_xvgr_string(ptr); } } } } else if (ptr[0] != '#') { if (nny == 0) { (*ny) = nny = wordcount(ptr); /* fprintf(stderr,"There are %d columns in your file\n",nny);*/ if (nny == 0) { return 0; } snew(yy, nny); snew(fmt, 3*nny+1); snew(base, 3*nny+1); } /* Allocate column space */ if (nx >= maxx) { maxx += 1024; for (k = 0; (k < nny); k++) { srenew(yy[k], maxx); } } /* Initiate format string */ fmt[0] = '\0'; base[0] = '\0'; /* fprintf(stderr,"ptr='%s'\n",ptr);*/ for (k = 0; (k < nny); k++) { strcpy(fmt, base); strcat(fmt, "%lf"); rval = sscanf(ptr, fmt, &lf); /* fprintf(stderr,"rval = %d\n",rval);*/ if ((rval == EOF) || (rval == 0)) { break; } yy[k][nx] = lf; srenew(fmt, 3*(nny+1)+1); srenew(base, 3*nny+1); strcat(base, "%*s"); } if (k != nny) { fprintf(stderr, "Only %d columns on line %d in file %s\n", k, line, fn); for (; (k < nny); k++) { yy[k][nx] = 0.0; } } nx++; } } gmx_fio_fclose(fp); *y = yy; sfree(tmpbuf); if (legend_nalloc > 0) { if (*ny - 1 > legend_nalloc) { srenew(*legend, *ny-1); for (set = legend_nalloc; set < *ny-1; set++) { (*legend)[set] = NULL; } } } return nx; }
int key_length(char phrase[]) { return wordcount(phrase) * HEX_CHUNK_LENGTH; }