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
ADVERTISEMENT
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
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
View Related
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
Sep 15, 2014
I'm not sure what the program's purpose is?
1) Ask the user to enter a sentence. Until you reach the end of the sentence, test each character to count the number of spaces and letters.
2) For every space counted, print "SPACE", then print one "!" for every letter counted on an indented line underneath the "SPACE".
Your test sentence to use is: "The potash feldspars are important rock-forming minerals in plutonic, volcanic, and metamorphic rocks."
HINT: You do not need any strings. You need one while loop and two for loops. <cctype>
View 4 Replies
View Related
Feb 11, 2013
I want to read sentence from command line. I open some program which run in command line and I have to wait for that program process. So , I don't know when process success .I can't type next command if can't read sentence from command. I use
Code:
wprintf(GetCommandLine());
but it show
"C:UsersPKRUdocumentsvisual studio 2010ProjectsVirus ScanDebugMyProgram
How to read sentence from Command line with MFC?
View 5 Replies
View Related
May 31, 2014
I have to write a program to reverse a sentence like
cat
tac
but my program is case sensitive. Like if i enter sentence it gives me ecntenes(which is wrong). How to make it non case-sensitive using vectors? (I cannot use #algorithims)
// BackWardsSentence.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
string BackWords (string sentence);
int BackSentence (string sentence);
[Code] .....
View 2 Replies
View Related
May 25, 2014
I had been tasked to create a program that reverses a word i.e.
cat
tac
How to make my program non case-sensitive using vectors?
Code:
// BackWardsSentence.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
string BackWords (string sentence);
int BackSentence (string sentence);
string BackWords1 (string sentence);
[Code] .....
View 2 Replies
View Related
Oct 20, 2014
I am now making a Dictionary using C++. My goal is to search the word and display the definition of the searched word from the text file. I have a code but it is not working. How can I search a word and display the definition of the word from a text file?
void searchFile(string word) {
ifstream ifile;
ofile.open("dictionary.txt", ios::in);
string line;
string search;
[Code] ....
View 1 Replies
View Related
Jan 28, 2015
Having problem with my code. i keep getting an error towards the bottom of the code. i need the user to enter a word. and with that word convert it to numbers. once i have convert it if it is bigger than 20 i have to add the two digits together and get print out the array that response to it.
example" ALEX
A=1
L=12
E=5
X=23
1+12+5+23= 41 //since its bigger than 20 you add 4 and 1 together so it will be 5. after that you print the 5th element of array
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
[Code]...
View 2 Replies
View Related
Apr 18, 2013
So I'm trying to reformat a paragraph where the first letter of each sentence is capitalized and the rest are lower case. This is my function thus far. I'm trying to read for the end marks . ! and ? and have it so that once the are encountered the next word is capitalized. I used ispunct initially but it read for things like ,'s as well.
int PunctCount(string Text)
//Counts the end marks. {
int Total = 0;
for (int i = 0; i < Text.length(); i++)
if (Text == '.' || Text == '?' || Text == '!')
Total++;
return Total;
}
Right now I get error: no match for âoperator==â in âText == '!'â
View 1 Replies
View Related
Apr 1, 2014
#include<iostream>
#include<cstdlib>
using namespace std;
int main() {
char *article[5] = { "the", "a", "one", "some", "any" };
char *noun[5] = { "boy", "girl", "dog", "town", "car" };
[Code] ......
View 4 Replies
View Related
Oct 29, 2013
#include <iostream>
#include <string>
#include <istream>
[Code]....
It seems like my program doesnt want to take in a sentence, only the first word i type in
View 1 Replies
View Related
Sep 12, 2013
My program will ask the user to enter the number of lines for the sentence "I will always use object Oriented programming. " if for example, the user enters 3, it should print out
I will always use object Oriented programming. I will always use object Oriented programming. I will always use object Oriented programming.
the second part of my program asks the user to enter the line which we want to make a typo. If they enter 2, it will replace the "I will always use object Oriented programming. " with "I will always use object Oriented programing." in the second line.
this is how it should look like but I am having trouble putting the second part together. I don't know how to remove the sentence and replace it with the second part.
Enter the number of lines for the punishment: 6
Enter the line for which we want to make a typo: 3
I will always use object oriented programming. I will always use object oriented programming. I will always use object oriented programing. I will always use object oriented programming. I will always use object oriented programming. I will always use object oriented programming.
View 1 Replies
View Related
Dec 28, 2014
So I'm working on that program that uses .txt files to store data, and I have one problem: I can't recover one full name from the .txt file
It's a school library program and it uses the <fstream> library for file operations, it stores theBookSignature >> theNameOfTheAuthor >> theBooksName.
I understand that C++ stops the input of a line when it stumbles upon a space, but isn't there something like a getline(cin, variableName) for file streams?
View 2 Replies
View Related
May 21, 2014
I am trying to write a program in which i enter sentences and then gives the reversed output
E.g.: -
INPUT
Enter the number of sentences
3
This is a sentence
Program
You are great
OUTPUT
sentence a is This
Program
great are You
I wrote the following code but its failing when im trying to enter a sentence
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
void str(char*, int);
void main() {
char *word[25];
[Code] ....
View 7 Replies
View Related
Nov 25, 2013
I am trying to write a code that reads all the words in text according to each sentence from a file. this means i have to signify the end and beginning of every individual sentence the text file. actually am trying to create a summarizer in c++.
View 5 Replies
View Related
May 31, 2014
I have to write a program to reverse a sentence like
cat
tac
But my program is case sensitive. Like if i enter sentence it gives me ecntenes(which is wrong). How to make it non case-sensitive using vectors?
// BackWardsSentence.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
string BackWords (string sentence);
[Code] ......
View 3 Replies
View Related
Feb 5, 2013
Im writing a c program that reverses the words in a sentence,
Example:
you can cage a swallow can't you?
you can't swallow a cage can you?
I have it all working, except the fact that I dont know how to get the words themselves to turn around. Heres my code and an example of the output im getting.
Output Im getting:
Enter a sentence: you can cage a swallow can't you?
Reverse of sentence: uoy t'nac wollaws a egac nac uoy?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX 200 /*Decent number of chars for a sentence*/
int main()
[Code] ....
View 2 Replies
View Related
Oct 31, 2013
so I'm creating a program that generates random sentences with structs..I'm trying to use structs and and create 4 different groupings article, noun, verb, and preposition. Then I'm trying to use "r = rand() % ;" to randomly pick one one word from each group to make a sentence. this is what i have
Code:
typedef enum article {
the = 1, a, one, some, any
} article;
typedef enum noun {
boy = 1, girl, dog, town, car
}
[code]....
View 5 Replies
View Related
Dec 23, 2013
I'm trying to get this program to work that will count the frequency of each vowel.
#include <iostream>
#include <string>
using namespace std;
int main(){
char sent[81];
cout << "Type up to an 80 character sentence." << endl;
cin.getline(sent, 81);
[Code] .....
View 2 Replies
View Related
Nov 29, 2014
I want to count all the vowels in a string (a, e, i , o, u) and display it as a text-based histogram for example:
[INPUT] The black cat sat up on the orange mat!
[OUTPUT]
A: *****
E: ***
I:
O: **
U: *
The asterisks are supposed to correspond to the number of vowels that are counted (using increments and the function setfill()).
#include <iostream>
#include <string>
#include <iomanip>
[Code]....
This is my output during compilation:
[OUTPUT]
The black cat sat up on the orange mat! 0 0 0 0 0
A:
E:
I:
O:
U:
View 1 Replies
View Related
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
Apr 15, 2014
I wrote this program:
#include <iostream>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
[Code] ....
LETTER OR '.' ? s
LETTER OR '.' ? f
LETTER OR '.' ? b
LETTER OR '.' ? e
LETTER OR '.' ? a
LETTER OR '.' ? g
LETTER OR '.' ? .
VECTOR : [ SFBEAG ]
SENTENCE ?
But after this i can't write anything. Do you know why? I've never had problems with getline... when i used cin >> it read but only one word. Now it doesn't even let read...
View 1 Replies
View Related
Dec 11, 2012
I've created a class that is supposed to store first name, last name, date of birth, date of death, and a fact about a person (all variables within the class). Im trying to fill these variables with a read function. it reads a .txt file like this
Firstname Lastname 1987 1988 this guy did this
The problem is, I don't know how to handle the last variable. the variable needs to hold the entire "this guy did this" sentence. i made it a string, just because i was clueless, and as expected, it only holds "this"
this is my .h:
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
class Person {
public:
Person();
Person(const Person & person);
[Code] ....
Here is the read function in the .cpp:
bool Person::Read(ifstream & input) {
return (input >> fname >> lname >> dob >> dod >> fact);
}
View 3 Replies
View Related
Sep 12, 2014
I thought maybe there was something in C that could read full sentences from stdin
Code:
scanf("%100[^
]s", string);
But that's not working for me. so i came up with my own function and its not giving me the results i want. here is the function including the call from main:
Code:
/* * * * * * * * * * * * * *
* FROM MAIN *
* * * * * * * * * * * * * */
printf("
Adding a new part...
");
printf("Enter part name: ");
get_string(new_part.pname);
[Code] .....
/* * * * * * * * * * * * * * * * * * * * * * *
* UNDESIRED OUTPUT *
* * * * * * * * * * * * * * * * * * * * * * */
8newpart
Where is the eight coming from? i thought fpurge clear the buffer. Also, I'm trying to add spaces in between words... i thought maybe putting within the while loop but outside of the if statement string[length +1] = '' would work, but it doesn't. so i put it outside of the loop but that i knew that wouldnt work either.
Problem #2 is reading from a file.. so far i have the following code which reads everything perfectly except the .txt file has a new line character at the end and i think its reading it:
Code:
/* * * * * * * * * * * * * * * * *
* READS FROM FILE *
* * * * * * * * * * * * * * * * */
if(read_in != NULL)
{
while ((fgets(read_string, MAX_PARTS ,read_in) != NULL) && (array_position < MAX_PARTS))
[Code] ....
0 in stock i want it to stop after reading the ball bearings line. a lot of issues for one post, but all related to reading inputs so i put it all on one.
View 2 Replies
View Related