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
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
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
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
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
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
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
Mar 20, 2014
so my question is i want to print characters,no string just an array of characters,i do this but it s not working,maybe i have to put the '' at the end?
Code:
int main() {
int i;
char ch[5];
for(i = 0; i < 5; i++) {
scanf("%c",&ch[i]);
[Code]...
View 6 Replies
View Related
Jul 6, 2014
Im supposed to find the common characters between two string characters, assuming that the user wont input duplicate letters like ddog. When I run my code I get an output of a question mark upside down. Here is my code with comments on what each part is supposed to do
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char str1[20], str2[20],remp = '