int main() { std::cout << countWords("Hello world!") << std::endl; std::cout << countWords("") << std::endl; std::cout << countWords(" ") << std::endl; std::cout << countWords(" Hello World! ") << std::endl; std::cout << countWords("I") << std::endl; }
int main(void) { const char text1[] = "Well, here goes."; const char text2[] = "And here we go... again."; printf("%s - words = %i\n", text1, countWords(text1)); printf("%s - words = %i\n", text2, countWords(text2)); return 0; }
int main(int argc, char **argv) { const char text1[] = "Well, here goes."; const char text2[] = "And here we go... again"; int countWords(const char string[]); printf("%s - words = %i\n", text1, countWords(text1)); printf("%s - words = %i\n", text2, countWords(text2)); return 0; }
int main (void) { const char text1[] = "Well, here goes."; const char text2[] = "And here we go...again."; const char text3[] = "This isn't to be counted as eight."; int countWords (const char string[]); printf ("%s - words = %i\n", text1, countWords (text1)); printf ("%s - words = %i\n", text2, countWords (text2)); printf ("%s - words = %i\n", text3, countWords (text3)); return 0; }
/*it takes main arguments */ int main(int argc, char **argv) { /* 1. 2. argumanalr duzgun ve bos olmamali */ /* calistirilabilir dosya ile file name arasinda . */ if ((argv[1] == NULL) || argc!=2) { printf("Yanlis Kullanim\n"); printf("Dogru yazim sekli\n"); printf(" ./hw02 directory\n"); return(-1); } /* Taking on internet stackoverflow for changing data value in processes */ totalWords = mmap(NULL, sizeof *totalWords, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); totalChildProcess = mmap(NULL, sizeof *totalChildProcess, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); /* Printing Console al information about program*/ countWords(argv[1]); printf("Total words = %d\n",*totalWords); printf("Total child process = %d\n",*totalChildProcess); printf("Total File which is search = %d\n",totalFile); printf("Total Directory in given directory = %d\n",totalDirectory); return 0; }
char* fileinfo_get(char* path) { FILE* file; xmlBufferPtr buf; xmlTextWriterPtr writer; char* ret; int wordCount; file = fopen(path, "r"); wordCount = countWords(file); fclose(file); buf = xmlBufferCreate(); writer = xmlNewTextWriterMemory(buf, 0); xmlTextWriterStartDocument(writer, NULL, XML_E, NULL); xmlTextWriterStartElement(writer, BAD_CAST "fileInfo"); xmlTextWriterWriteFormatElement(writer, BAD_CAST "wordCount", "%d", wordCount); xmlTextWriterEndElement(writer); xmlTextWriterEndDocument(writer); ret = malloc(buf->size); strcpy(ret,(char*)buf->content); xmlBufferFree(buf); return ret; }
int main(int argc, char** argv) { //Check input. if (argc < 3) return -1; std::ifstream in(argv[1]); if (!in) return -1; StrIntMap w; // Count the occurence of each word and store the result in the map w. countWords(in, w); std::ofstream myfile; myfile.open(argv[2]); // Output the occurence of each word from the map (alphabetically). for (StrIntMap::iterator p = w.begin();p != w.end(); ++p) { myfile << p->first << "\t" << p->second << "\n"; } myfile.close(); return 0; }
int main (void) { char text[81]; int totalWords = 0; int countWords (const char string[]); void readLine (char buffer[]); bool endOfText = false; printf ("Type in your text.\n"); printf ("When you are done, press 'RETURN'.\n\n"); while ( ! endOfText ) { readLine (text); if ( text[0] == '\0' ) endOfText = true; else totalWords += countWords (text); } printf ("\nThere are %i words in the above text.\n", totalWords); return 0; }
static void testLazyDog(const bool verbose = false) { const QString s = "The quick brown fox\njumps \t\tover\t\t the lazy dog.\n"; const auto view = StringView{s}.trim(); const auto words = view.countWords(); if (verbose) std::cout << "# words: " << words << "\n"; TEST_ASSERT(words == 9); const auto nonSpaceChars = view.countNonSpaceChars(); if (verbose) std::cout << "# non-space chars: " << nonSpaceChars << "\n"; TEST_ASSERT(nonSpaceChars == 36); if (verbose) std::cout << "---\n"; int seenWords = 0; for (const auto &w : view.getWordsAsQStrings()) { if (seenWords++ > 0) { if (verbose) std::cout << " "; } if (verbose) std::cout << "[" << w.toStdString() << "]"; } TEST_ASSERT(seenWords == words); if (verbose) { std::cout << "\n---\n"; std::cout << std::flush; std::cerr << std::flush; } }
int main(int argc, char* argv[]) { if(argc != 2) { printf("Must give a file name to execute: ./main <file_name>\n"); return -1; } /* Open File Input */ FILE *fpr = fopen(argv[1],"rb"); if(fpr==NULL) { return -1; } int wordCount = 0; int lineCount = 0; size_t len; char *line; while(getline(&line,&len,fpr) != -1) { wordCount += countWords(line); lineCount++; } fclose(fpr); printf("Word Count: %d\n",wordCount); printf("Line Count: %d\n",lineCount); return 0; }
static void WiggleReaderPop(WiggleIterator * wi) { WiggleReaderData * data = (WiggleReaderData*) wi->data; char line[5000]; if (wi->done) return; while (fgets(line, 5000, data->file)) { if ( !strncmp("variableStep", line, 12)) { data->readingMode = VARIABLE_STEP; WiggleReaderReadHeader(wi, data, line); continue; } else if (!strncmp("fixedStep", line, 9)) { data->readingMode = FIXED_STEP; WiggleReaderReadHeader(wi, data, line); continue; } switch (countWords(line)) { case 4: data->readingMode = BED_GRAPH; WiggleReaderReadBedGraphLine(wi, line); break; case 2: if (data->readingMode != VARIABLE_STEP) { fprintf(stderr, "Badly formatted fixed step line:\n%s", line); exit(1); } WiggleReaderReadVariableStepLine(wi, line,data->span); break; case 1: if (data->readingMode != FIXED_STEP) { fprintf(stderr, "Badly formatted variable step line:\n%s", line); exit(1); } WiggleReaderReadFixedStepLine(wi, line, data->step, data->span); break; default: fprintf(stderr, "Badly formatted wiggle or bed graph line :\n%s", line); exit(1); } if (data->stop > 0) { if (wi->start >= data->stop) { wi->done = true; return; } else if (wi->finish > data->stop) { wi->finish = data->stop; } } return; } fclose(data->file); data->file = NULL; wi->done = true; }
// d) int main(void) { char hamlet[] = "to be or not to be, that is the question: whether 'tis nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles, and by opposing, end them? to die: to sleep; no more; and by a sleep to say we end the heartache and the thousand natural shocks that flesh is heir to, 'tis a consummation devoutly to be wish'd. to die, to sleep; to sleep: perchance to dream: ay, there's the rub; for in that sleep of death what dreams may come when we have shuffled off this mortal coil, must give us pause: there's the respect that makes calamity of so long life; for who would bear the whips and scorns of time, the oppressor's wrong, the proud man's contumely, the pangs of despised love, the law's delay, the insolence of office and the spurns that patient merit of the unworthy takes, when he himself might his quietus make with a bare bodkin?"; int totalWords = countWords(hamlet); int b, c; zeilenEnthaelt(hamlet, b, c); wortAusgeben(hamlet, c, b); return 0; }
int main (void) { const char text1[] = "Well, here goes."; const char text2[] = "And here we go... again."; const char text3[] = "We're already done..."; const char number1[] = "123,456"; const char number2[] = "-12,345"; int countWords (const char string[]); printf ("%s - words = %i\n", text1, countWords (text1)); printf ("%s - words = %i\n", text2, countWords (text2)); printf ("%s - words = %i\n", text3, countWords (text3)); printf ("%s - words = %i\n", number1, countWords (number1)); printf ("%s - words = %i\n", number2, countWords (number2)); return 0; }
// . set words from a string // . assume no HTML entities in the string "s" // . s must be NULL terminated // . NOTE: do not free "s" from under us cuz we reference it // . break up the string ,"s", into "words". // . doesn't do tags, only text nodes in "xml" // . our definition of a word is as close to English as we can get it // . BUT we also consider a string of punctuation characters to be a word bool Words::set( char *s, bool computeWordIds ) { reset(); // determine rough upper bound on number of words by counting // punct/alnum boundaries m_preCount = countWords ( s ); if ( !allocateWordBuffers( m_preCount ) ) { return false; } return addWords( s, 0x7fffffff, computeWordIds ); }
TEST(WordCountOpenMPTest, FileParAndSeqTest) { pair<const char*, size_t> text = loadTextFromFile("book.txt"); auto counted1 = countWords(text.first, text.second); auto flipped1 = flipMap<string, int>(counted1); auto counted2 = countWordsOpenMP(text.first, text.second, defaultThreadCount); auto flipped2 = flipMap<string, int>(counted2); ASSERT_TRUE(std::equal(flipped1.rbegin(), flipped1.rend(), flipped2.rbegin())); }
int enxii() { char frase[] = "hola mundo."; int words; words = ( frase[ 0 ] != '.' )? ( 1 + countWords( frase, 0 ) ) : ( 0 ); printf("\nLa cantidad de palabras es: %i\n\n", words ); return ( 0 ); }
void AbstractTwoLevelAgreement::overLapNamesFinished(const SelectionList & tagWords, const SelectionList & outputWords,int &numWords) { if (tagWords.size()==0 && outputWords.size()==0 ) return; bool underComputation=(&numWords==&underNumWords); int countCommon=commonWords(text,tagWords,outputWords); //not working correctly on maximal boundaries int countCorrect=countWords(text,tagWords); int countDetected=countWords(text,outputWords); assert (countCorrect!=0); assert (countDetected!=0); numWords+=countCorrect; double recall=(double)countCommon/countCorrect * countCorrect, precision=(double)countCommon/countDetected *countCorrect; if (countDetected==0) precision=0; if (underComputation) { underBoundaryRecallList.append(recall); underBoundaryPrecisionList.append(precision); } else { boundaryRecallList.append(recall); boundaryPrecisionList.append(precision); } }
bool StrChrFieldSearcher::matchDoc(const FieldRef & fieldRef) { bool retval(true); if (_qtl.size() > 1) { size_t mintsz = shortestTerm(); if (fieldRef.size() >= mintsz) { _words += matchTerms(fieldRef, mintsz); } else { _words += countWords(fieldRef); } } else { for(QueryTermList::iterator it=_qtl.begin(), mt=_qtl.end(); it != mt; it++) { QueryTerm & qt = **it; if (fieldRef.size() >= qt.termLen()) { _words += matchTerm(fieldRef, qt); } else { _words += countWords(fieldRef); } } } return retval; }
int main(int argc, char** argv) { Link* wordLinkedList; FILE* fp = fopen(argv[1], "r"); // Open file for reading numLinks = countWords(fp, &numLinks); // Go through text file and return the number of words/tokens found to allocate mem for printf("Done counting number of words. Found:%d\n",numLinks); makeLinkedList(fp, wordLinkedList, numLinks); // Make a linked list out of the words in the opened text files fclose(fp); //Sort the LinkedList, alphabetically, by using insertion sort algorithm return 1; }
TEST(WordCountTest, FileTest) { pair<const char*, size_t> text = loadTextFromFile("book.txt"); auto counted = countWords(text.first, text.second); auto flipped = flipMap<string, int>(counted); wordStatFlipped m = {{20304, "и"}, {10198, "в"}, {8428, "не"}, {7822, "что"}, {6453, "на"}}; ASSERT_TRUE(std::equal(m.rbegin(), m.rend(), flipped.rbegin())); }
int countWords( char texto[], int pos ) { int cont; cont = 0; if( texto[ pos ] != '.' ) { cont = countWords( texto, pos + 1 ); if( texto[ pos ] == ' ' ) cont++; } return ( cont ); }
int main() { const int STR_LENGTH = 80; char cString[STR_LENGTH]; std::cout << "Enter a string of no more than " << STR_LENGTH - 1 << " characters: " << std::endl; std::cin.getline(cString, STR_LENGTH); int wordCount = countWords(cString); std::cout << "There are " << wordCount << " words in the string you entered." << std::endl; std::cin.get(); return 0; }
std::vector<QString> StringView::getWordsAsQStrings() const noexcept(false) { const auto numWords = countWords(); assert(numWords >= 0); std::vector<QString> result{}; result.reserve(static_cast<size_t>(numWords)); auto tmp = *this; tmp.trim(); while (!tmp.isEmpty()) result.emplace_back(tmp.takeFirstWord().toQString()); assert(static_cast<int>(result.size()) == numWords); return result; }
bool Words::setxi ( char *s , char *buf, long bufSize, long niceness ) { // prevent setting with the same string if ( m_s == s ) { char *xx=NULL;*xx=0; } reset(); m_version = TITLEREC_CURRENT_VERSION; // save for sanity check m_s = s; m_localBuf2 = buf; m_localBufSize2 = bufSize; // determine rough upper bound on number of words by counting // punct/alnum boundaries m_preCount = countWords ( s , niceness ); if (!allocateWordBuffers(m_preCount)) return false; bool computeWordIds = true; return addWords(s,0x7fffffff, computeWordIds, niceness ); }
main() { char str3[64], str4[64], str5[64]; //Count words printf("\n\nCount Words: "); readString(str3); printf("Word Count: %d", countWords(str3)); //Find longest word printf("\n\nFind longest word: "); readString(str4); printf("Longest Word: %d", longestWord(str4)); //Most number of vowels printf("\n\nFind most vowels: "); readString(str5); printf("Most vowels: %d", mostVowels(str5)); return 0; }
int main(int argc, char **argv) { if (argc < 2) return (EXIT_FAILURE); std::ifstream in(argv[1]); if (!in) exit(EXIT_FAILURE); StrIntMap w; countWords(in, w); for (StrIntMap::iterator p = w.begin(); p != w.end(); ++p) { std::cout << p->first << " occurred " << p->second << " times.\n"; } }
int main() { unsigned long linecount=0; unsigned long wcount = 0; unsigned long chcount = 0; unsigned long n = 0; string s; set <string> lines, words; bool newLine = true; char c; while (getline(cin,s)){ if(s.empty()){ linecount++; chcount++; if(newLine){ newLine=false; n++; } } else{ linecount++; //add new line lines.insert(s); chcount = chcount + s.length(); chcount++; wcount = countWords(s,words)+wcount;// call function } } cout<<linecount<<"\t";//line count cout<<wcount<<"\t"; //word count; cout<<chcount<<"\t";//character count cout<<lines.size()+n<<"\t";//unique lines cout<<words.size()<<endl;//unique word return 0; }
// . set words from a string // . assume no HTML entities in the string "s" // . s must be NULL terminated // . NOTE: do not free "s" from under us cuz we reference it // . break up the string ,"s", into "words". // . doesn't do tags, only text nodes in "xml" // . our definition of a word is as close to English as we can get it // . BUT we also consider a string of punctuation characters to be a word bool Words::set ( char *s , long version, bool computeWordIds , long niceness ) { // prevent setting with the same string if ( m_s == s ) { char *xx=NULL;*xx=0; } reset(); m_version = version; // save for sanity check m_s = s; m_version = version; // determine rough upper bound on number of words by counting // punct/alnum boundaries m_preCount = countWords ( s , niceness ); if (!allocateWordBuffers(m_preCount)) return false; return addWords(s,0x7fffffff, computeWordIds, niceness ); }
int main(void) { char text[81]; int totalWords = 0; bool endOfText = false; printf("Please enter your text\n"); while(!endOfText) { readline(text); if(text[0] == '\0') endOfText = true; else totalWords += countWords(text); } printf("Total Words: %i\n", totalWords); return 0; }
TEST(WordCountTest, ConstStringTest) { const char* text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit." " Curabitur at sollicitudin risus. Proin id dictum ex. Cum sociis" " natoque penatibus et magnis dis parturient montes, nascetur" " ridiculus mus. Donec porta felis magna, eu fringilla sapien porta" " consectetur. Vestibulum sagittis, dui sit amet sagittis posuere," " augue tellus mollis mauris, id ornare."; auto counted = countWords(text, strlen(text)); auto flipped = flipMap<string, int>(counted); int wordsTotal = 0; for (auto it: flipped) { wordsTotal += it.first; } ASSERT_EQ(wordsTotal, 50); wordStatFlipped m = {{2, "amet"}, {2, "consectetur"}, {2, "id"}}; ASSERT_TRUE(std::equal(m.begin(), m.end(), flipped.rbegin())); }