Visual C++ :: Vector Input / Counting Words
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
ADVERTISEMENT
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
View Related
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
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
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
Jul 19, 2013
I have read that the Erase-remove idiom is the way to go. I have a rough understanding of how this works but am unsure whether I can implement a match-counter along with it.
For counting alone, I would use something like this:
Code:
std::vector<std::string> v; // contains duplicate strings in different elements
std::string term = "foo"; // search term, changing at runtime as well
unsigned int matches = 0;
for( auto e : v ) {
if( e == term ) {
[Code] .....
I'm not sure how (or if) I can combine the two things. That is, I don't know how to integrate a function comparing two (changing) strings into the remove_if() method. Nor do I know how to increment a counter during iteration.
The vector is extremely large, so speed is paramount. I think there are many other avenues for optimization, but decreasing the vector's size for each consecutive search could deliver a big speed boost for subsequent searches I imagine, as traversing it holds the biggest cost.
View 3 Replies
View Related
Feb 11, 2013
I need to write a program using at least one while loop to count and display the amount of vowels in a user input string. This is what I have so far.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int acounter(0); // Create counters for each vowel
[Code] ....
View 2 Replies
View Related
Jan 10, 2014
I'm doing an exercise that prints all input lines that are longer than 80 characters. I rather not use any libraries so I decided to write my own function that counts characters to use it in my main program. However when integrate things my function returns zero all the time.
Here is my full code:
/* Exercise 1-17 Write a program to print all input lines that are longer than 80 characters */
#include<stdio.h>
/* Declarations*/
#define MAX_STRING_LEN 1000
int count_characters(char S1[]);
int main() {
[Code] .....
So I was trying to debug my count_characters() function and this is the code if I was to run it seperately:
Code:
#include <stdio.h>
/* counts character of a string*/
main() {
int nc = 0;
int c;
for (nc = 0; (c = getchar()) != '
'; ++nc);
printf("Number of characters = %d
", nc);
}
which works...
View 1 Replies
View Related
Apr 14, 2013
i am trying to create a c++ program that asks for an input and determines if it is a question or not by searching each word from the input across a database (txtfile)..so far I have managed to make it search the database for the word but it only works on one word.... i would like to be able for it to search every word on the input separatly..here is the code:
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
[code]....
View 4 Replies
View Related
Aug 13, 2013
The basic idea of this exercise is to generate words from a user-input, seven-digit number(a phone number). The code runs, but for some reason, I can't get it to print the numbers into the file.
Code:
/*Write a program that will generate a word based on a randomly generated, seven-digit number. there should be 2187 possible words. Avoid "phone numbers" that begin with 0 or 1*/
#include<stdio.h>
#define PHONE 7
void wordGenerator(int number[]);
void wordGenerator(int number[]) {
//loop counters for each digit in the number
[Code] ....
View 3 Replies
View Related
Feb 5, 2013
I'm trying to write a short program that takes the input from a user and trims any leading/trailing white space, and then checks how many words are in the string. Problem is, I'm only allowed to use stdio.h and stdlib.h. How can I accomplish this? Also, how would I check if any of the characters which were entered aren't either a number, letter, or '-'?
View 3 Replies
View Related
Mar 4, 2014
Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a vertical orientation is more challenging.
See [URL] ....
I'm trying to do this exercise from K&R on my own (with my own code), but I'm receiving a signal (Illegal instruction (Core dumped)) when the input is too large.
#include <stdio.h>
#define MAXWORDLENGTH 10
int main(void) {
int c; /* Character read */
long length[MAXWORDLENGTH + 1];
int reading_word = 0;
int word_size = 0;
[Code] ....
Where the problem might be occurring. I tried debugging with GDB but found no useful information.
Program received signal SIGILL, Illegal instruction.
0x00007ffff7a3b76e in __libc_start_main (main=0x4005d4 <main>, argc=1,
ubp_av=0x7fffffffe2a9, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7fffffffe298) at libc-start.c:258
258libc-start.c: No such file or directory.
The program output is also wrong when tested with the code provided at the link given above.
View 7 Replies
View Related
Nov 16, 2013
I've reached a point in "Jumping into C++" where I need to make a program that converts input numbers into their word equivalent.
So far I've made it work for numbers 0-9999. I've tried implementing 10000-99999 but there are problems with the order of the words printed (57865 would print fifty thousand seven thousand eight hundred sixty five). But besides that, the program is absolutely enormous (for me) and I'm wondering if it can be shortened. Keep in mind I can only use loops and if statements so far. Here it is:
Code:
#include <iostream>
#include <string>
void extras(int e);
void digits(int x);
void tens(int xx);
void hundreds(int xxx);
void thousands(int xxxx);
//void tens_of_thousands(long xxxxx);
[Code]....
View 6 Replies
View Related
Apr 20, 2014
I trying to get input from the user and split into words that separated by a space.
string s = "1 2 3";
istringstream iss(s);
int n;
while (iss >> n) {
cout << "* " << n << endl;
}
The code above works fine but i want to get the string from user. the code below only prints the first word and trashes rest of the words in the sentence.
string s ;
cin>>s;
istringstream iss(s);
string n;
while (iss >> n) {
cout << "* " << n << endl;
}
View 2 Replies
View Related
Nov 24, 2012
The user will first enter the file name to be processed. The program can do the following 5 tasks:
1. Count the number of words
2. Count the number of alphabets (without punctuation marks)
3. Count number of sentences.
4. Count the frequency of each vowel.
5. Count frequency of the following three words individually: FAST, computer and engineering
There should be a proper menu through which the user can select the desired task. The program should continue until the user asks to terminate it.
Here is what i have done so far:
#include <iostream>
#include <cstring>
#include <fstream>
#include <cstdlib>
using namespace std;
int main(void)
{
int opt=0; //option number
ifstream fin;
string filename;
[Code]...
There are a few problems.
1- When I enter option 'q', an infinite loop starts.
2- The first time, the program gives the correct value. After that, each time it gives answer ZERO.
3- The last part is not working. I experimented something which failed. I don't know how to do the last part.
View 1 Replies
View Related
Feb 21, 2014
I have program that is supposed to read in a story from an input file and separate the words and output the lines on which the word occurs. It needs to read in another input file that has a list of words (1 per line) to ignore. i.e. skip them when running through the story. This is what I have so far, I've changed multiple things trying to get it running....
#include<iostream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<string>
#include"split.h"
[Code] .....
View 1 Replies
View Related
Sep 21, 2013
I'm getting this when I compile my program. Then, when the program runs I get an error. I assume it is because I have the warning for this problem. How can get around this error.
warning C4172: returning address of local variable or temporary
Code:
#include <iostream>
#include <cstring>
using namespace std;
[Code]....
View 10 Replies
View Related
Apr 21, 2013
My program , it says there is no problem with the build but when exe. it displays a bunch of backward 'k' instead of reversing the words entered.
Problem: Enter in a C-string and use function to display the word backward. (it might work with a pointer but I am not sure how to go about it)
lab10_p2.cpp
View 4 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
Sep 8, 2014
I have been given an assignment to make a code to read some text nd display all the words nd the number of times they appear in another file or as output without displaying the repeating words. I made the code but its not giving any output.
#include<iostream>
#include<conio.h>
#include<fstream>
#include<string>
using namespace std;
void read(string);
string x,z,w;
[Code] ....
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
May 4, 2013
I can`t seem to store multiple values into my vector when a user keys in an input. Lets say a user inputs 1,2 as the first set and later keys in 3,4.
My vector gets overridden by 3 and 4. I'm trying to pass these values into a function to store them into a vector and use them in the function.
Below is my code snippet
int reconstructSecret(int x, int y) {
int getX,getY;
getX=x;
getY=y;
vector<int> myXCordVec;
vector<int> myYCordVec;
[Code] .....
View 6 Replies
View Related
Sep 30, 2013
How would you search in a vector array from a user input string?
ex: user input : "Hello"
output: search vector array and find the line that has the string "Hello" and output the array "Hello" is on?
View 1 Replies
View Related