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


ADVERTISEMENT

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 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++ :: 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 :: How To Print Characters But No String Just Array Of Characters

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

C/C++ :: Find The Common Characters Between Two String Characters

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 = '';
int size1,i,j,temp;
printf ("Input the first string");

[Code]...

View 6 Replies View Related

C :: Comparing Of Characters In Given String From Input String?

Feb 7, 2013

I am stuck in this program, Be given a string of chars, where each single char belongs to the following alphabet: a..zA..Z0..9 (So, in the string there are only lowercases, uppercases and digits. No blank, no comma, ...). For every char of the given alphabet, count how many times in the string

1-- the char belong to a sequence of identical chars whose length is at least three (i.e.: in the string cc74uyrpfccc348fhsjcccc3848djccccc484jd for three times the character 'c' satisfies this condition)

Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>

[Code]...

2-what is the longest substring of characters strictly rising interm of ASCII code(the following is greater (>) of the previous)

3- what is the longest substring of successive characters interm of given string rannge (i.e.: fhkjshdfruytyzABCDEfglsj => 7)

View 1 Replies View Related

C++ :: Reading Characters From String

Apr 13, 2013

i have a string which is n characters long. i need to read say 20 characters at a time, wait for the user to type OK and then send another 20 characters. wait for the user to type OK and send 20 characters again until we get to the nth character.

View 3 Replies View Related

C++ :: Removing Characters From A String

Nov 1, 2013

I want to remove a particular character from a string. Say '.'. I've tried the following:

void removeDots(std::string &x)
{
std::remove_if(x.begin(),x.end(),[](char c){return (c == '.');});
}

This has the effect of removing the dots but keeping the length of the string the same, so old characters are left over at the end. Is there an extra action to do to x to make it the right size or is there a better way of doing it?

View 3 Replies View Related

C/C++ :: How To Uppercase All Characters Of A String

Oct 28, 2014

I'm working on a programming challenge and i need to uppercase all characters of the string.

string upperCaseIt(string& name){
for(int index = 0; index < name.length(); index++){
name[index] = toupper(name[index]);
return name;
}
}

My problem is that it only uppercase the first character of the string.

View 2 Replies View Related

C/C++ :: How To Cout The String Characters Themselves

May 11, 2014

Iam working with arrays and i cant get to the write solution to cout the characters.

the Question is : Write a program that inputs a character string from the user as an input (using cin.get())and store it in myStr[ ] array.Assume that the length of the input string is less than 100 characters and the string may contain lower case, upper case, and/or symbols.The program should then print the number of lower case, upper case, digits, and symbols along with the characters themselves.

my code :

#include <iostream>
#include <string>
#include<iomanip>
using namespace std;
int main() {
int ctr1=0, ctr2=0, i=0, ctr3=0;

[Code] ...

What i have now, how can i cout the uppercase characters and the lower case characters and the symbol characters !

View 3 Replies View Related

C/C++ :: How To Ignore Certain Characters In A String

Sep 18, 2014

I am trying to cout just the first 5 characters the user enters into a string. I'm not sure how I can discard or not show the rest of the characters they try to enter after 5.

#include <iostream>
#include <string>
using namespace std;
int main() {
string random;
cout << "Enter any word." << endl;
cin >> random;
cout << random; //want to ignore everything after first 5 characters entered.
return 0;
}

View 1 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 :: Entering Characters Into A String Pointer

Feb 8, 2013

1. The debugger shows that the characters are entered into the word pointer, and when a punctuation or space character is encountered, I terminate the string with a ''. But when I use puts to print the string, garbage is printed. Why is this?

2. Also, if I don't allocate memory for word the compiler gives a warning about it being used uninitialised. But I didn't allocate memory for the array of pointers(words), and the compiler didn't give any warnings. Whats the difference between a pointer and an array of pointers?

Code:

// wordcount.c - count words.
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

[Code]....

View 7 Replies View Related

C :: Copying Characters From One String To Another With Pointers?

Apr 14, 2013

So I'm writing a function isPalindrome() that can accept a string as an argument, and copy from it only the alphabetic characters in the argument (original) string to another string named alpha_array which contains only the alphabetic characters. Then the function should be able to call the isPurePalindrome function to determine if alpha_array is an ordinary palindrome.

The problem is that when I call isPalindrome in main, the program crashes.

Here's the code I have for isPurePalindrome and isPalindrome:

Code:

/* 1 */
int isPurePalindrome( const char * sentence ) // Can accept strings, array and pointer arguments
{
// Declarations

[Code].....

View 4 Replies View Related

C :: Create A Function That Will Take A String Of Characters

Dec 7, 2013

I can not cope with the task.Create a function that will take a string of characters (including spaces) and print the numbers of characters (including commas, periods, etc.) in it. The output will be arranged alphabetically. Distinguish case sensitive!

View 6 Replies View Related

C :: Print String With Escape Characters

Mar 7, 2013

is there any function to print a string with all the escape characters in it?

For example, instead of printing:
This is a string.

It would print:
This is a string.

Or in Windows:
This is a string.

I know that you can debug the code to find the variable contents, but is there any way to accomplish this with some standard library function?

View 6 Replies View Related

C++ :: Error Reading Characters Of String

Feb 2, 2013

#include<fstream>
#include<Windows.h>
#include<cstdlib>
#include<iostream>
#include<string>
#include<iomanip>
#include<sstream>

using namespace std;

void add_matrix(int row1,int row2,int col1,int col2,double m1[30][30],double m2[30][30],double m3[30][30]);

[Code] .....

This program is suppose to read a matrix file , and the first getline is suppose to get the file header but it appears that 'line' doesn't take in any value other than empty thus causing all the problem , I tried to put cin.getline() in front of it to take away the /n created by the cin before it , but it doesn't work . When I debug the program when the arrow points to the string line , this error appears

line<Error reading characters of string.>std::basic_string<char,std::char_traits<char>,std::allocator<char> >

I tried to initialize string line=NULL too , doesn't work either.

View 1 Replies View Related

C++ :: Reading String 2 Characters At A Time?

May 10, 2013

may i know how do i read a string 2 characters at a time?

lets say i have a for loop like this

for(int i=0;i<stringLen;i++)
{
for(int j=0;j<???;j++)
{
//insert code
}
}

what i want to do is i want to read a string 2 characters at a time and store them into a vector.

View 3 Replies View Related

C/C++ :: Count Numbers And Characters In A String

Sep 2, 2014

I have a upcoming C++ exam. I would like to write a program to convert INDIVIDUAL digits into words.

E.g 678 = six seven eight[/size][/b]

I have the following code:

//Program to print individual digits in words
#include<iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number between 0 and 9999: ";

[Code] ....

View 7 Replies View Related

C# :: Splitting Characters Within String Array

Sep 23, 2014

I have the following string array

string[] output= input.toArray();

each index has a set of two characters, for example:

output[0] has 'th', output[1] has 'is'

I want to take t and h and compare them or do anything with them, but it must be in pairs.

I tried foreach but I don't know if there is a way to compare the element with the next element .

View 2 Replies View Related

C/C++ :: String Prints Unusual Characters?

Sep 10, 2014

The print statement below I commented prints out unusual characters. I have two strings from the command line that I pass to the TKCreate function. Inside the function the strings print out fine, but when I return a pointer to the struct back to the main method one of the strings prints out fine, but the other one prints out unusual inconsistent characters.

#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>

[Code]....

View 10 Replies View Related

C++ :: Finding If String Has Unique Characters

Mar 28, 2013

bool isUnique(string _str)
{
bool char_set[256];
int len = _str.length();
memset(char_set, '/0', 256);
for(int i = 0; i < len; ++i)

[Code] .....

I came across this code to find if string has unique characters...i didnt understand why they subracted ascii value of character '0' in the statement int val = _str[i]- '0' and what is happening with the statements...

if(char_set[val])
{
return false;
}
char_set[val] = true;

I take each character in the sting and traverse the whole string .and if count is 2 i use break and conclude that its not unique and not otherwise...can i use this method or this is not efficient????

View 8 Replies View Related







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