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


ADVERTISEMENT

Visual C++ :: Backward Function - Reversing Words Entered?

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

C++ :: Reversing A String

Feb 26, 2015

I have this bit of code that reverses a string but there's a bit of it that I just don't understand:

int main()
{
char sentence[20]; //Create char array
void reverse( const char * const sPtr );
printf( "Enter your text please:
" );

[code]....

I just don't get how this bit results in the entered string being reverse.how to make code look like code.

View 6 Replies View Related

C :: Reversing A String Using Pointers

Nov 13, 2013

everything seems to be right in this program except that the puts() function does not print anything.

Code:

/*c program to reverse a string using pointer*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
}

[code]....

View 4 Replies View Related

C++ :: Reversing N Characters In A String?

Dec 26, 2013

I have a string like str="ABCDEFGHIJK";

need o/p like this str="CBAFEDIHGJK"

am getting "CBA" correctly after that its not printing anything.

int main()
{
string str="ABCDEFGHIJK";
char str1[10],rev[10];
int n=str.length(),count=0,c=3,k=0,j=0;

[Code].....

View 10 Replies View Related

C++ :: Reversing String Using Seek / Tell?

Aug 8, 2012

I have an assignment that asks me to write a program which reads all lines from a text file (one by another), reverses them and write to the same file. I also have a pseudocode with which I have to work and it is as follows:

While the end of the file has not been reached

pos1 = current get position
Read a line.
If the line was successfully read
pos2 = current get position
Set put position to pos1.
Write the reversed line.
Set get position to pos2.

I have tried many things and the code misses letters. Below you can see my code:

Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main() {
fstream file;
file.open("output.txt");

[code]....

This is the text with which I have to work:

Mary had a little lamb
Its fleece was white as snow
And everywhere that Mary went
The lamb was sure to go.

And this is what I get:

bmal elttil a dah yraM
Itswons sa etihw saw eceelf
Antnew yraM taht erehwyreve d
T.og ot erus saw bmal eh

View 7 Replies View Related

C/C++ :: Reversing A String / Char Array

Aug 12, 2013

I'm new in the C programming language, so I tried to create a program that reverses a string. This is my code:

/* Reverse string */
#include <stdio.h>
#include <string.h>  
int main() {
  char s[8]="Welcome";  
 
[Code] ....

The output of the program is "@".

View 5 Replies View Related

C/C++ :: Reversing String Loop - Compiler Error

Feb 13, 2014

I need to reverse this loop. get how to do it in order but when i have to reverse it i get a compiler error

int main() {
cout << "Enter 3 cities" << endl;
string cities;
for ( int i = 0; i < 3; ++i ) {
getline(cin, cities[3];

[Code] ....

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

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







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