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


ADVERTISEMENT

C Sharp :: Assign A Specific Number To Each Letter In A Sentence?

Feb 14, 2014

I have a string - a whole sentence that I want to assign a number to each letter, space, comma and period etc. So all "A's" will have the same number, all "B's" will have another number etc. I don't want to use the ASCII numbers because they all need to be sequential and some of the punctuation isn't. I have put the string into a char array to separate each character out and was thinking about running it through a loop with if statements for each letter and assigning numbers there and then saving the numbers in the order they appear into a list as a string but I keep coming up with errors so I don't know how to do it or if there is a better way to accomplish what I'm trying to do.

View 1 Replies View Related

C++ :: Reverse Words In A Sentence

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

C++ :: Getting The Words (strings) Of A Sentence?

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

C :: Reverse The Words In Sentence Program

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

C++ :: How To Display Words Splitted From A Long Sentence

Apr 8, 2013

How can i display words form a long sentence.

example :(lets assume that if u find two spaces that is word)

INPUT: the Indian school boys are very good compare to other countries.

OUTPUT: the Indian
school boys
are
very
good
compare to
other countries

I am solving these way but it takes only one space to divide a word.

#include <string>
#include <vector>
#include <fstream>
#include <iostream>
int main() {
std::vector <std::string> words;

[code] .....

View 1 Replies View Related

C++ :: Count Numbers Of Words In A Sentence Simply By Counting Spaces

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

C/C++ :: Delete From Sentence All Words With Character Count Which Is Equal To Pair Number

Nov 20, 2014

I have an assigment to make program which deletes from sentence all words with character count which is equal to pair number , for example - [ I like C ] and the result of this program should be [I C] because the word like contains 4 characters which is pair and it should be removed.

So I started writing my program and I am stuck at this block of code -

#include <stdio.h>
#include <stdlib.h>
main () {
char text[100], blank[100];
int c=0,d=0,i,j;
gets(text);

[Code] ....

To explain what is happening - I go through all string and search for first ' ' space symbol and check its value. If it is pair then my program prints that it is not pair[because last character before space had not pair number of characters], but the hardest part comes in when i have two not pair words , because space takes one character and now when i check if i%2 == 1 the answer is false [0] for the second word .

View 2 Replies View Related

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++ :: 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++ :: 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 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++ :: 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++ :: One Letter Of A String Comparison

Jan 21, 2013

I just would like to turn this into cpp:

string eg("azertyFTW");
if(eg[one of the letters contained in this string] == 'c') {
cout << "eg has the letter c in it";
} else {
cout << "not this time :(";
}

View 4 Replies View Related

C++ :: How To Loop Through A String And Uppercase Each Letter

Apr 28, 2013

tell me how to loop through a string and uppercase each letter?

View 1 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++ :: 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++ :: Scan Through One String To Find A Letter That Also Appears In Another?

Feb 3, 2015

I need a code that will search through string 1 and find the first place with a letter that also appears in string 2 and return the pointer of that place. This is what I wrote:

char strPbrk(const char *s1, const char *s2) {
char p = *s1;
for (int i = 0; i < strlen(s1); i++)
for (int j = 0; j < strlen(s2); j++)
if ((p+i) == *(s2+j))
return p;
return NULL;
}

but it continues to return wrong values idk what I'm doing wrong.

View 4 Replies View Related

C++ :: Find Adjacent Same Letter In Randomly Generated String?

Jan 29, 2013

I need a simple adjacent_find() to find the adjacent same letter in a randomly generated string?

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 :: Reversing String Not Words

Oct 2, 2014

I am trying to write a program in C to reverse a string .

Example - This is America
output - America is This

I have thought of two ways of doing this question

1) using 2D arrays ( no pointer)
2) Using Strings and pointer

Code:
#include<stdio.h>
#include<string.h>
main()
}

[code]....

View 4 Replies View Related

C :: Print Words Of A String

Dec 4, 2013

I want to print the words of a sentence, given as a string..But I have a problem with the end of the sentence, and cannot find the bug....

Code:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
char str[80]="This is a sentence";
int main(){
}

[code].....

View 7 Replies View Related

C++ :: Delete Words From A String?

Feb 3, 2015

"Type a function that take in a string containing numbers and others characters and print on stdout all the numbers contained into the string, where for number is mean every maximal numerical sequence, of numbers not separed by spaces. Numbers printed on exit must be separated by commas. For example, if i put in the function the string "paje27hg78 2k f562" my function must print:

27, 78, 2, 562 "

So i started my code like so: (I WANT TO NOTICE THAT WE HAVE ONLY USED IOSTREAM AND FSTREAM LIBRARY FOR NOW, SO DON'T USE OTHERS LIBRARY ELSE MY TEACHER WON'T CORRECT MY HOMEWORK!)

#include <iostream>
#include <fstream>
using namespace std;

[Code].....

View 18 Replies View Related

C/C++ :: Replace Words In String

May 19, 2014

I have a challenge to replace all the words "you" in a sentence that is entered by a user to "u". I have got this working but my code is also changing yourself to urself which it should not be doing.

#include <iostream>
#include <string>
using namespace std;
string shortenMsg (string smsP) {
string sentence = smsP;
string word1 = "you";
string word2 = "u";

[Code] .....

View 3 Replies View Related

C++ :: Find First 10 And Last 10 Words Of String Array

Jan 26, 2015

I got a homework that require to count number of words in a text file and also display the first and last 10 words of the text file to the console. I have finished the counter problem and now I struggle showing the first and last 10 words.

#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
int tokenize(string sentence, string tokenizedWords[]);

[code]....

View 2 Replies View Related

C++ :: Counts Number Of Words In A String That End With Ng

Dec 10, 2013

I am trying to write a code that counts the number of words in a string that end with ng.

I started with this but this just checks the end of the string. I need it to check everyword in the string and also count them up.

int main() {
string s;
cout << " enter string ";
getline(cin, s);
string end;
end = s.substr(s.length()-2, 2);
cout << end;
cout << endl;
return 0;
}

View 19 Replies View Related







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