how do i increment a string array?
like a becomes b, x becomes y?
ex. Hello world becomes ifmmp xpsme.
This is a discussion on string array within the C++ Programming forums, part of the General Programming Boards category; how do i increment a string array? like a becomes b, x becomes y? ex. Hello world becomes ifmmp xpsme....
how do i increment a string array?
like a becomes b, x becomes y?
ex. Hello world becomes ifmmp xpsme.
An array of chars is actually an array of 1 byte numbers.
The ASCII table lists the character representations of these numbers. If you don't have that chart handy, just look for yourself:
char c = 0;
while(c < 127) {
printf("%c = %i \n", c, c);
getch();
c++;
}
So really, it's just a matter of looping through the string and incrementing the value of each char. That's basically it.
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}
If you are using the STL, you can do it with std::string and the transform algorithm:
Code:#include <string> #include <algorithm> #include <iostream> using namespace std; class IncrementString { public: inline char operator()(char c){ return ++c; } }; int main() { string str("Hello World"); cout<<"String before transform: "<<str<<endl; transform(str.begin(), str.end(), str.begin(), IncrementString()); cout<<"String after transform: "<<str<<endl; return 0; }
how about any word inputted in the c++ program? just any other word becomes all the letters in the word incremented