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


ADVERTISEMENT

C/C++ :: To Delete Words (The) From Stream

Dec 14, 2014

I need to use getchar and putchar. The task is simple to say but not that easy to implement as it may seem. I end up with:

char c = 0, c_ = 0, c__ = 0;
while ((c = getchar()) != '.') {
if (c == 't') {
c__ = c;
c = getchar();

[Code] ....

If the word "the" is followed with another one, the last isn't eliminated. I enter "thethe" and get "the", what is not right.

View 1 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

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/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

C++ :: Reverse Alternating Words In A String

Nov 24, 2014

I'm trying to create a small program to reverse every alternate words in a string.

OUTPUT: The esoum was thgauc in a peg.

#include<iostream>
#include<string>
using namespace std;
int main() {
string sentence, reversed_sentence, buffer;

[code].....

View 6 Replies View Related

C++ :: Unable To Reverse Even Words In A String

Nov 25, 2014

I'm trying to reverse every even word in a string (not all of it). But I keep getting an empty output.

For example:

The mouse was caught in peg.
The esmou was thgauc in gep.
Underlined words (even words)

#include<iostream>
#include<string>
using namespace std;
int main()
{
string text, result, temp;
int word_count(0);
cout << "Enter a sentence: ";

[Code]...

View 1 Replies View Related

C++ :: Reverse Alternate Words In A String

Nov 23, 2014

How do reverse every alternate words in a string that I read into my program:

e.g. The mouse was caught in a clothes peg.
reversed (including the full stop)
The esoum was thguac in a clothes gep.

I could program it to reverse the whole sentence. But no clue how to reverse certain words such as every even word. Do I need a function and/or loop to solve this?

#include<iostream> // allow input and output
#include<string> // allow for larger entries of characters
using namespace std;
int main() {
string sentence, reversed_sentence;

[Code] ....

View 4 Replies View Related

C/C++ :: Count The Number Of Words In A String?

Apr 28, 2015

#include <fstream>
#include <iostream>
#include <string>

[Code].....

When I try to run my program I get:

1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>C:UsersDocumentsVisual Studio 2010ProjectsCS 111Lab10Lab10DebugLab10.exe : fatal error LNK1120: 1 unresolved externals

What I'm trying to do is get my program to count the number of words in an inputted data file. I've attached the assignment directions

Attached File(s) : lab10_data_.zip (9.27K)

View 4 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++ :: Instead Of String - Accept Answer With Space In Between Words

Jun 13, 2014

string answer;
cout<<"5.Newton's which law states that F=ma?";
cin>>answer;
if (answer == "newton's second law")

[Code].....

View 6 Replies View Related

C++ :: How To Recognize Two Words Entered By User For A String

Feb 11, 2013

In my little experiment i am trying to get the compiler to recognize 1 word with 2 parts from a list of names.

For example: if the user wanted to choose "candy bar", from a list of items which include: "candy bar", "cat", "dog"

My current code can recognize words without a space like cat and dog. But how can i recognize candy bar?

I tried using getline but its of no use.

View 2 Replies View Related

C/C++ :: Read In String With Multiple Words And Numbers?

Jul 23, 2014

I am trying to read user input for recipe ingredients which must include a ingredient name, and may include a quantity and a unit. Example: Stone ground flour 2 cups or Sugar 1 Tbsp or Milk. The problem I am having is that the string gets cut off after a space when multiple words are used for the ingredient name.

cin.ignore();
string line;
getline(cin, line);
istringstream record(line);
string name;
string name2;
int quantity = 0;
string unit;
record>>name>>quantity>>unit;

View 1 Replies View Related

C/C++ :: Comparing Two String Arrays For Unique Words?

Oct 2, 2014

I'm looking to take in an array of less than 50 strings, and I want to find all of the unique words in that array (omitting the words that are repeated) and then outputting the unique words and unique word count. My code compiles, but my unique array is couting all of the words contained in the original array regardless of uniqueness.

#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
cout << "Please type in some words." << endl;
cout << "Type END and return when you are finished." << endl;

[code].....

This is what I get back.

You typed the following 14 words: red, green, blue, red, red, blue, green, blue, orange, red, reg, apple, banana, banana, END,

You typed the following 0 unique words: red, green, blue, red, red, blue, green, blue, orange, red, reg, apple, banana, banana, END

I'm not worried about the unique count yet, I just want to get the unique array containing the correct strings.

View 3 Replies View Related

C/C++ :: Find Repeated Words In String And Symbols Between Them

Oct 29, 2013

I need to find 2 similar words in one sentence and i need to find how much symbols are between these two words. I can't figure out the algorithm.

For example sentence would be-

This is nice table and nice chair.

Similar words are- nice

Symbols between them are 11 or 8(dont know if space is count as symbol)

int main()    
char text[200],*dist;
printf("Enter one sentence 
 ");
gets(text);

Maybe first of all would be

dist=strtok(text, " ,.!?");
while(dist!=0)
{
 printf("%s
", dist);
 dist=strtok(NULL, " ,.!?");
 }  

and it wil output each word and maybe then can search for similar words if there would be 2 strings then i would use strstr but i dont know how to do with one string.

View 1 Replies View Related

C/C++ :: How To Delete Part Of The String

Nov 26, 2012

I have the following string: "type computer {dell}"

And I want to remove the {dell}

So that the output on the screen type computer

Or delete any clause between the two brackets {}

How do i do that ?

View 5 Replies View Related

C/C++ :: Delete Last 4 Characters From Given String

Mar 29, 2012

x="A4478596895";

Delete last four characters.

View 5 Replies View Related

C :: Creating Program That Can Pick Words In A String Or Array

Apr 24, 2013

Creating a C program that can pick words in a string or array and save it in different location, later combine everything in one string or array. It will be using simple programming C code. For example (arrays, pointer) but not interrupts or other string functions.

In a sentence like this:
Size= 70
$--GSV,x,x,x,x,x,x,x,...*hh $--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,b,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh $--GLC,xxxx,x.x,a,x.x,a,x.x,a.x,x,a,x.x,a,x.x,a*hh $--GSA,a,a,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x.x,x.x,x.x*hh

The program must capture the $--GGA string then extract from this string:

1) hhmmss.ss
2) IIII.II
3) a (if a = to N or S replace N or S with + or - respectively )
4) yyyyy.yy 5) b (if b = to E or W replace E or W with + or - respectively )

Save them in an array and display as well. After all the saving, the program should combine them to one string. That the final output.

View 7 Replies View Related

C++ :: Formatting User Input And Check How Many Words Are In String

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

C++ :: Forming Unique String With Single Occurrence Of Words

May 10, 2012

I am trying to form unique string from other string which is having multiple presence of same word as,

string testA = "one
two
three
four
one
seven wo";

now new string should contain single occurrence of words "one" and "two" so that new string will look like,

string testB = "one
two
three
four
seven"

View 3 Replies View Related

C :: How To Delete All Occurrences Of A Char In A String

May 17, 2014

I want do delete all occurrences of a char in a given string, but I really don't see my error in the code. Here is how I did it:

Code:

char *input = "example_string";
int len = strlen(input);
char *new_line[len];
char bad = 'e'; //the one to delete
int i;
int j = 0;

[Code]...

I get segmentation or bus errors.. And I also don#t understand the warning I get. new_line is an array of chars, and I am trying to assign to it a certain char.

View 5 Replies View Related

C :: Delete Comma And Semicolon In The String?

Nov 12, 2013

So I need to read a file that has this input and need to delete the comma and semicolon in the string but idk how to ignore the comma and semicolon:

ex of input file: A firstname, lastname; 13

I did this:

Code:
i = 0;
fscanf (fData, "%c", &grade);
fgets(space,2,fData);
do{
fgets(name,50,fpData);
i++;
}while(temp[0] == ';');
temp[i] = temp[i - 1];
fscanf (fData, "%d", &age);

View 4 Replies View Related

C++ :: Count Number Of Words And Lines Then Print All Words

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







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