C++ :: Outputting First Word Of Each Sentence In String

Dec 20, 2014

I have been trying to get this to work for a while now - with no success.

Basically I am trying to write a function which the returns the first word of each input sentence in a single string - this is part of a larger cryptography program I am working on.

So for example, if this string was passed into the function:

"This is what I mean. Is it right? A poor puppy abandoned. Secret torturing of dogs are happening. Message: be on the watch."

It should return:

//declared in class "steganalyse"
string cyphertext;
string punctuation = ".?!;:'";
book is_first_word

[Code] .....

But this only returns the first word:

This

Any other way to return the first word of each sentence in a string.

View 1 Replies


ADVERTISEMENT

Visual C++ :: Ask User To Enter A Sentence And Then A Word To Be Searched For In Sentence

Oct 9, 2013

I am trying to write a program that ask the user to enter a sentence and then a word to be searched for in the sentence. The program must then search for the word in the sentence in a loop and continue to output each place the word is found. For example if the sentence is : I like pickles, pickles, pickles

and you searched for pickles it would return pickles found at 7, pickles found at 16, pickles found at 25.

I am having trouble writing the equation to make the find keep searching after each occurrence of the word being searched. Here is the code I have so far

HTML Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string paragraph;

[Code] ....

View 5 Replies View Related

C++ :: String Copy - Program To Reverse Word Order In Sentence

Apr 2, 2012

I am trying to write a program that takes a sentence and reverses the word order.

For instance This is a Bird would become Bird a is This

Code :

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main (void) {
char input_buffer[1024];
char middle[1024];

[Code] ....

View 3 Replies View Related

C :: Word Length Statistics For A Sentence

Oct 25, 2014

Write a program that calculates statistics on word length for a sentence. The sentence isterminated by a ',' For each found length of a word the number of words of that length is printed. Only those lengths that are found in the input are printed. Only letters from a-z or A-Z are allowed to form words. Words are separated by a space. No punctuation characters other than ',' are allowed. If any other input character is recognized or the input is longer than 80 characters the program displays "NOT VALID" (see Hints).

Note, that in the case that no word is present in the input, nothing is printed.

% u6_stats

Enter a sentence: Bolt was expected to use the super bark.

Length 2: 1
Length 3: 3
Length 4: 2
Length 5: 1
Length 8: 1

% u6_stats

Enter a sentence: Something wasn't right.
NOT VALID

Thats what i've already done.

Code:
#include <stdio.h>
#include <conio.h>
void main() {
char s[100];
int numOfWords, lengthOfWord = 0;

[Code] ....

So, the problem is that if i inpute a text like"abc abcd abc abc" the result will be like

"length 3: 3 length 4: 1 length 3: 2".

So when the program already compared 1st (here 3) element with others, this element will not be comparing again, but i have the 3d element with same length, and it that case, the program compare it with remained elements and print 2. How can i rework my code, if i don't wont to compare already compared elements.

Second problem is that i need to get results from lowest length till highest.

View 2 Replies View Related

C++ :: String Outputting Twice?

Nov 3, 2014

When I run the program, the prompt I am giving the user before I collect their data, shows up twice in row. Here's the part of the code I'm referring to:

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
// method prototypes
void characterInstructions();
void phraseInstructions(); //

[Code] ....

View 6 Replies View Related

C++ :: Capitalize First Character Of Each Sentence In String

May 31, 2013

Write a function that accepts a pointer to a C-String as an argument and capitalizes the first character of each sentence in the string. For instance, if the string argument is "hello. my name is Joe. what is your name?" the function should manipulate the string so it contains "Hello. My name is Joe. What is your name?" Demonstrate the function in a program that asks the user to input a string and then passes it to the function. The modified string should be displayed on screen. Optional Exercise: Write an overloaded version of this function that accepts a string class object as its argument.

#include<iostream>
#include<cctype>
#include<cstdlib>
using namespace std;
void capitalize(char sentence[], int const SIZE);

[Code]...

Not even sure if I'm headed in the correct direction, but I'm getting the following errors:

E:CPT-233Sentence Capitalizer.cpp In function `void capitalize(char*, int)':
34 E:CPT-233Sentence Capitalizer.cpp call of overloaded `strstr(char&, const char[2])' is ambiguous
note E:CPT-233<internal>:0 candidates are: char* std::strstr(const char*, const char*) <near match>
note E:CPT-233<internal>:0 char* std::strstr(char*, const char*) <near match>

what I'm doing wrong?

View 2 Replies View Related

C++ :: Censor 4 Letter Words String Within Sentence

May 16, 2014

I have a problem with my code. You are given a sentence and you should censor the 4 letter words within the sentence.

#include<iostream>
#include<string>
using namespace std;
int main () {
int N;
cin>>N;
int k,j,counter=0;

[Code] ....

View 1 Replies View Related

C/C++ :: Find Length Of First Sentence In Input String

Feb 13, 2015

I have a question about finding the length of first sentence in an input string.

For example, let the input string be: dream in code. community learning

The length of first sentence is 13 (blanks are included). My question is how to create conditions for multiple punctuation signs (!,?)? If while loop goes like:

while((str[i]!='.')||(str[i]!='!')||(str[i]!='?'))

it gives me an error for infinite loop.

Code:
#include<stdio.h>
int main() {
char str[100];int i=0,br=0;
printf("enter a string:");
gets(str);

[Code] ....

View 1 Replies View Related

C++ :: How To Know If A Word Is Before Another In A String

Nov 18, 2013

I would like to know how I can know if a word is before another in a string. Here's my current code.

#include <iostream>
#include <math.h>
#include <string>
#include <cstdlib>
#include <sstream>
#include <vector>
#include <iterator>

using namespace std;
int main() {

string equation;
getline (cin, equation);

[Code] .....

View 9 Replies View Related

C :: Print First Word Of The String

Apr 12, 2013

1. Create a variable named index and nitialize it to zero(0)
2. Prompt for and input a string value from thekeyboard. Store the string inthe string variable newstring[80].
3. While (newstring[index] does not equal ‘’).

i. Display the character at newstring[index] followed by a NL
ii. Increment index ====================================== ...

And this is what i have done so far and i dont know where I am wrong ...

Code:
#include<stdio.h>
int main()
{
int index = 0; //initialize index to zero since first elementin an array is numbered zero
char newstring[80];

[Code] ....

View 3 Replies View Related

C++ :: Finding And Displaying A Word From A String?

Mar 2, 2014

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
//Program Goal
//Have 3 Strings to represent 3 categories
//Have the user type in their name
//Have the user type in a full sentence how they are feeling
//Program should find the word in the user inputted sentence and display an appropriate response

[Code]...

View 4 Replies View Related

C++ ::  How To Verify If A String Equals A Certain Word

Apr 3, 2013

I want to see if the value of a string equals a certain text. But I can't make it. There are two problems :

1) It seems 'tolower' doesn't work with strings. What to use then?
2) When I delete tolower, it works, but I have an output of "You didn't enter 'add'" even when I do enter 'add'. What's the problem? Is it due to the null byte? What to change?

#include "stdafx.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[]) //This was added automatically by Visual Studio.

[Code] .....

View 3 Replies View Related

C++ :: How To Read A String And Then Compare It To A Word

Mar 5, 2014

I'm trying to read a string and then compare it to a word.

My code:

char* cmd = "start";
std::cin >> cmd;
if (strcmp (cmd, "eval"))
eval ();

When the program gets to the cin part, it breaks.

View 4 Replies View Related

C++ :: How To Turn A String Word Into Letters

Dec 9, 2013

I'm having trouble trying to turn a word into letters. I've seen other posts but they deal with a sentence and it only outputs the words only. What I want to know is how do they take a word (Ex: "word") and break it into individual letters, where I want to store them in a vector of string?

If it's not too much trouble, I would prefer without using pointers or "std:: " marks, since I am trying to avoid pointers and I'm using "using namespace std" all the time.

Ex:

In the example "word", it should output into:

"w"
"o"
"r"
"d"

and I will push them back into a vector of string where each vector element contains a letter.

View 2 Replies View Related

C# :: Capitalize First Letter In Every Word In A String?

Jan 7, 2014

I have a difficulty with string methods for some reason. I tried solving a question from my book, which requires me to capitalize the first letter of every word in a string. I kept trying for maybe two hours yesterday, re-reading the string chapter to see if I'm forgetting a certain method or if something similar was discussed in the examples but I didn't find anything. I also googled it, and found a few answers, none of which I understood. They mostly had keywords or methods I wasn't familiar with. Anyway, here's where I am so far.

class Program {
static string UpperCase(string s) {
int place; string b, st1, st2,st3; char letter;
for (int i = 0; i <= s.Length - 1; i++) {
if (i == 0) {

[Code]....

The code compiles without any errors, but when I enter a string it capitalizes correctly for the first two words and then it starts capitalizing letters in the middle of the words.

View 14 Replies View Related

C/C++ :: Find Last Longest Word In A String

Apr 29, 2015

How to find the last longest word in a string when there are more of them (with the longest size)?

Here is the program for the longest without checking if last:

#include<stdio.h>
#include<string.h>
int main() {
char a[50],b[20],c[20];
int i,j=0,l=0;
printf("Enter a string:
");
gets(a);

[Code] ....

View 6 Replies View Related

C++ :: Capitalize Every Other Word In A User Input String

Nov 14, 2014

I've been agonizing over this all day. The assignment is to capitalize every other word in a user input string.

My logic is as follows:

1. I have the program get each character until it encounters white space (using for loop)
2. Then it should capitalize each character after the white space until it encounters another white space (using while loop).

My problem though is when i try to create a condition for while loop i have to terminate is when white space is encountered, but the very first character to start the while loop is a white space..

I was told to define boolean values, but after trying a few boolean conditions I'm still stuck..

Code:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

[Code] .....

View 5 Replies View Related

C++ :: Differentiate A Word / Letter And Number In A String

Aug 22, 2014

I have one string from user. Let say,

"The deviceId is 2"....but user also can give input like this..
"The deviceId is a".

I just need to know how to differentiate a word/letter and number in the string.

View 1 Replies View Related

C/C++ :: Word Maze - Find String In Vector

Mar 4, 2015

This program is to solve a word maze and find the number of words in the maze from a dictionary file.

The program runs, but stops by finding 1,2 and 3 letter words.

#include<iostream>
#include<vector>
#include<fstream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
vector <string> dict,forward,reverse;

[Code] .....

I also tried to find words using the entire vector as a container, the synopsis code that also did not work is below

while(j<dict.size()) {
if(dict[j].size()>2) {
if (std::find(forward.begin(), forward.end(), dict[j]) != forward.end()) {
cout<<"found word "<<dict[j]<<endl;

[Code] ....

Attached File(s)

dumpling2.txt (2.54K)

Dictionary.txt (718.34K)

View 13 Replies View Related

C++ :: How To Take Out Specific Combination Of Word Form A String

Feb 23, 2014

Suppose I have to take "100" from the string "1001", whats the process to do it?

View 6 Replies View Related

C++ :: Find String To Erase Symbol From The End Of A Word

May 2, 2013

I'm trying to use the find string to erase a ' ' from the end of a word. I tried something along the lines of:

if (SecondSide.find('
')!= string::npos)
SecondSide.erase(SecondSide.find('
'));

but it had no effect.

View 7 Replies View Related

C++ :: Take User Input As String And Test To See If Matches A Word

Dec 4, 2014

I'm creating a program that takes user input in the form of a string and tests to see if it matches a word. Each correct word will increase their score by one. Here is a portion of the code that is not working.

...
else if(s == 32) {
if(!currentLetter.empty()) {
currentLetter.erase(currentLetter.length() - 2, currentLetter.length() - 1);
} if(currentLetter.compare(oWord) == 0) {

[Code] .....

To me, this looks like it should do a very simple task as intended-take a String, compare it to another, and reset the word if they match or output incorrect if not. But, I'm not sure if there is some quirk in C++ with Strings, because this code always outputs Incorrect. Please try again. and the score never increases. I also tested this by literally setting the strings equal in the code, which still resulted in it not doing what it's supposed to.

View 3 Replies View Related

C++ :: Convert Full Word To Uppercase If It Is Lowercase In A String?

Feb 28, 2014

The problem I am facing is that I have to output the C++ input file and display every line of code in the output, except in the output I have to convert every if, else, and while as IF, ELSE, WHILE. I tackled the first part and now its onto the 'easier' part even t

View 1 Replies View Related

C++ :: Input String And Then Convert Each 1st Letter Of Word Into Capital Case

Dec 10, 2014

Write a program that inputs a string and then converts each 1st letter of a word in the string into capital case. An example run of the program is shown below:

Enter string: introduction to programming
Output string: Introduction To Programming

View 1 Replies View Related

C++ :: Hangman Definition Game - Extract Word Randomly Form File And User Guess The Word

Jun 25, 2014

Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.

I'm having trouble receiving that random word and I'm getting the definitions from the file.

Here's my code:

#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

[Code] ....

This is what is in the words.txt file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet

View 3 Replies View Related

C :: Display Function Displays All Letters Of Word Entered Instead Of Word Itself

Feb 18, 2013

I am building a linked list and i need to display function i have. The display function displays all the letters of the word entered instead of the word itself. below is my struct, one of my functions and the display function.

Code:

//-----------struct ------------//
struct Node
{
char data;
struct Node *next;
}*Head;

[code]....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved