C++ :: Algorithm Of Words Counting
Jun 28, 2012
This code is compile but must have some upgrades :
1. The algorithm count double space how 1 word this is not correct. Probably have to add condition like ' '&'a-z'||'A-Z' but in unknown to me reason this is don't work
2. If there is one words without space then counted don't detect this word, it is incorrect.
Code:
#include <iostream>
using namespace std;
int main () {
char ch;
cout <<"enter your text: " ;
[Code] .....
View 7 Replies
ADVERTISEMENT
Apr 12, 2014
I am writing a program when the beginning it you have to pick which step to preform out of a few steps. Once you choose the step. The user is asked to input what is asked and it should preform it. I have completed most of my steps but the one step giving me a hard time is converting a user inputed sentence into all lowercase letters, and then count the words of it. My program starts out like this if you pick this step Code: else
if (choice == 3) {
/* Gather user's input */
printf("
You have chosen to convert a sentence to all lowercase letters and count the words
"
"Enter the sentence: ");
gets ( sentence );
Call the function to convert the whole sentence to lowercase and count the number of words */
lowercase_string ( &sentence);
countSentence ( &sentence);
} /* End if statement */
this is the easy part in which I presume I did correctly, but now this is where I am getting the problems:
/* Prompts user to enter a sentence and convert it to lowercase and count the number of words */
void
countSentence (char *sentence)
void
lowercase_string (char*)
{
[code]....
I want to output the original sentence, then the sentence with all lower case letters, then at last output the number of words in the sentence. I declared all my variables up top, and I am wondering where my mistake is. When trying to compile it, I only get syntax errors which I don't understand.
View 8 Replies
View Related
Sep 29, 2013
I need to count Words in a string in <stdio.h> and <string.h> format ONLY, must be in WHILE Loop! Our professor acts like were programming students when were just marketing students
View 2 Replies
View Related
Mar 6, 2015
I'm trying to read files, count words in the files and go in directories. The problem is how I return numbers of total words and total directories. When it comes to nftw(), I am little confused.
Code: /*
*
*
*
* Usage:
*
* ./countWord <path>
*/
#define _XOPEN_SOURCE 700
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
[Code] ....
View 7 Replies
View Related
Mar 20, 2013
I am writing a program for my class in C++. For this program we are required to use different fuctions and prototypes outside of main. We have to determine the number of characters, lines, sentences, digits, words, etc. in a particular function the user types in.
View 1 Replies
View Related
Feb 3, 2014
I am trying to write a program that counts specific words that a user inputs "Howdy/howdy/Whoop/whoop" (yes I go to Texas A&M, hence those specific words) I am having an issue where it wont count the first word even if it is "Howdy"
For example if I put it:
"Howdy howdy whoop Whoop" - it only outputs that it counted 3 words
now if I were to do:
"Hello Howdy howdy whoop Whoop" - it would count 4.
Code:
#include "std_lib_facilities_4.h"
int main(){
cout << "Please enter desired words, when you have entered all words, please type CTRL+d (EOF Command)
" << endl;
//It was assumed that EOF command was going to be used here hence the necessity of 'CTRL+d'
vector<string>words;
[Code] ...
View 2 Replies
View Related
Dec 17, 2013
I have to write a program (on linux) which will count character, words and lines like wc linux command. I'm trying to write this for last 3 days... First part of app I did and it works fine - command line options to choose. Then I've got a function read_file which I have to use to read a file. One of the options is to get the file name from user and if user will not type any name then the standard file is ubuntu dict file /usr/share/dict/words, this is not working as well...
Counting characters and lines is working fine but because I don't know how to get text from read_file wrote code to read file interior this functions. Words counting is working partly - everything is fine until there are two or more spaces, tabs one after another then counts extra words. Finally I need child processes in words and lines counting functions. Parent process should waits for all childs to finish and should be pipes to submit character counts back to parent process. How to do all this things with processes...
Code:
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
/*size of character buffer to read in a file. */
#define BUFFSIZE 1000000
[code]....
View 2 Replies
View Related
Jun 1, 2013
My maze algorithm must be able to count total steps. He is not allowed to "jump" from a deadend back to the cross-way he originally came from.
Code:
int R2D2Turbo::findIt(Labyrinth* incLab, int x, int y){
if ((x == incLab->getExit().x) && (y == incLab->getExit().y))
{
return 1;
[Code] .....
Due to the nature of recursive algoirthms, he jumps instead of moving the way back from the deadend one by one... The only solutions I could think of are way overloaded...
View 3 Replies
View Related
Jan 22, 2014
I wrote a code that counts numbers of words in a sentence, simply by counting spaces... but instead of showing a true number it shows a wrong number.
#include <iostream.h>
#include <conio.h>
int check(char eh[10000]) {
int he=0;
for (int i=0; i<=10000 ;i++) {
[Code] ....
View 8 Replies
View Related
Dec 20, 2013
I have written below program to count number of words and lines and print the all the words.
#include <iostream>
using namespace std;
#include<fstream>
#include<string.h>
int main() {
ofstream outfile;
[Code] .....
Its compiling fine but when executed its displaying I infinite times...
View 3 Replies
View Related
May 19, 2013
I was reading this earlier [URL] ..... and I was trying to figure out how to pick one of the words randomly from my text instead of using all the words in it.
View 4 Replies
View Related
Aug 19, 2013
I am learning C programming from K & R text . i dont understand the wordcounting programing . How is working ?
Code:
#include<stdio.h>
#define IN 1
#define OUT 0
main()
[Code].....
View 6 Replies
View Related
Jun 19, 2014
So I'm supposed to create a program that will read off words from a .txt file,and use a function to count the number of vowels in each word and then display the specific vowels and their frequencies. ex. if the word is: butter the output would be:
a:0
e:1
i:0
o:0
u:1
This is what I have so far, but I'm running into some problems.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void PrintFrequencies(string str);
[Code]...
View 3 Replies
View Related
Apr 23, 2013
How I would go about counting lines from a file at the same time as extracting words? I need to know the line number to output what line the word is misspelled on. I tried getline and using sstreams but I could not get it to work.
void SpellCheck::checkValidWords(const string& inFileName) {
string eachword;
ifstream istream;
istream.open( inFileName.c_str() );
if ( !istream.is_open() ) {
[Code] .....
View 3 Replies
View Related
Nov 21, 2013
Write a program in C/C++ that counts and summing the elements (numbers) from the given interval in the array.
View 3 Replies
View Related
Mar 21, 2014
I now know how to count integers with while loop but I'm not sure how to count the integers with array.
So the question is:
1. program should keep reading integers as long as the integers are within [0,9999]
2. when user typed the integer not between 0 to 9999, the program print out the numbers of integers that were typed.
Sample
3
3
3
9999
9999
-1
You entered 3 3 times.
You entered 9999 2 times.
#include <iostream>
using namespace std;
int main() {
int i=-1;
int x;
int numbers[10000];
[Code] ....
I cannot use "do" ....
View 1 Replies
View Related
May 26, 2014
counting the occurrence of a number in my program.
Here's My Code:
void sort(int num[], int& count)
{
//cout << " Using Sort!";
for(int i =0; i <= count; i++)
[Code].....
How Can I continuously call the Count(); Function again after the first number?
View 3 Replies
View Related
Mar 1, 2014
#include <windows.h>
int main() {
int i;
int y=6;
int x=9;
gotoxy(x,y);
//gotoxy(x,y) must be the coordinate that the number lies in.
[Code] ...
How to make this program that the output is a number that counts up to infinite (or we say just like a timer but there's no minute just all whole number counting up ) using for loop ? and when the number changes it also change in color !
and the color of a number is according to the color attribute of console output.
View 2 Replies
View Related
Feb 10, 2015
I am unsure how to write a function which modifies the content of the 1D character array and counts the number of the vowels. the following is the array that i have.
char text[MAX+1] = {'T', 'e', 's', 't', 'e', 'r', EOT};
the output that i am trying to produce is should look something like this
the number of vowels is 2, e, e.
I am unsure how to do this.
View 3 Replies
View Related
Nov 7, 2014
I'm trying to write a program that should output, in a tabular form, the name of the algorithm, size of the array, number of comparisons and number of swaps. I am really, really, really bad at arrays and comprehending how to output variables from several. Especially in tabular form />
Here is what I have written thus far:
#include <stdio.h>
#include <stdlib.h>
#define MAX_ARY_SIZE 10
[Code]......
My questions:
1 - How do I make the array size change from 10 to 100 to 1000?
2 - How do I populate the array's with random non-repeating numbers?
3 - How do I make each algorithm count the # of comparisons and swaps?
4 - How do I return the counted comparisons AND swaps (in one return function??) and then print them?
View 6 Replies
View Related
Jul 12, 2013
This function check a set of values from a text file and show it on the output.
void MatchNumber(int b){
vector<Rect> rects;
ifstream theFile("CheckNumber.txt");
[Code]......
I want to calculate how many times the number is repeated. So I have used freq[num] in that function. But I am getting the output like this-
The common number is = 5
The 5 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times
The common number is = 4
The 4 repeated = 1 times
The common number is = 5
The 5 repeated = 1 times
The common number is = 5
The 5 repeated = 1 times
The common number is = 8
The 8 repeated = 1 times
The common number is = 9
The 9 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times
The common number is = 8
The 8 repeated = 1 times
So the value of freq[num] only shows 1 instead of calculating the number of repetition.
View 3 Replies
View Related
Nov 7, 2014
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
int num;
int count = 0;
[code]...
The last number in the numbers.txt file is: -1, and I am not allowed to include it in the calculation of total, average, etc.
I tried to make an if statement to not include -1 but, I can't figure it out. This compiles with or without my num == -1 statement.
View 3 Replies
View Related
Apr 28, 2014
I have the following code that does not work. It prints out 1 when it should print out 5 and 3 respectively. I know that the code is not the pretties due to ( *arr == value) but i am just learning C++.
Spoiler
template <typename T>
int countOccurrencesRecursively(T* arr, int size, T value){
//the base case is when the the array is empty
if(size == 0) return 0;
else return *arr == value + countOccurrencesRecursively(++arr, --size, value);
[Code] .....
View 2 Replies
View Related
Jan 19, 2012
So here is a function.. now I need to find how many times LINE 1, LINE 2, LINE 3 executes:
for (int i = 0; i <= n; i++) {
CODE 1;
stateCount1++;
for (int j = n; j > 0; j = j-3) {
[Code] ....
For CODE 1, its n+1. But I am having trouble finding the number of executions for CODE 2 and CODE 3.
View 1 Replies
View Related
Feb 22, 2015
I have recently hit a stump with C++ and have been getting pretty frustrated with this assignment. I just can't seem to find out how to start the assignment. Basically for the first part of the assignment, I need to find the number of characters in this .txt file my teacher provided for me. The only exception is that I can only count the actual letters themselves, not spaces or punctuation. How would I go about doing this? I have read about functions like isalpha but can't figure out on how to fit them into code to do the first part of this assignment.
View 2 Replies
View Related
Feb 2, 2015
it looks like a popular method for determining the total lines in a file is to read the entire file character by character in search of ' '. I have a file with 5 lines, but for some reason this code isn't finding any instances of ' '. Is this possible? Is there a better way to get the number of lines in a file?
The file looks like this:
Code:
NAME: John
FRIEND 1: Steve
FRIEND 2: Andrea
FRIEND 3: Ken
OCCUPATION: Programmer
Code:
FILE *f = fopen(currentFile, "r");
if (f == NULL) perror ("Error opening file.
");
int ch, lines = 0;
while(!feof(f)){
[Code] .....
View 2 Replies
View Related