-
reversing a string!
(c/c++)
is it possible to reverse a string with strrev when the string is longer than 1000 characters?
please note that i only want to use strrev() and no loops or anything else!
------------------------------------------------------------------------------------------------------------------------
This message will self destruct in 5 seconds starting from ....
-
Hrm, I don't know. But why don't you take any random 1000 character string, and test it. Thats the easiest way to find out. :)
-
maybe i have not explained it right :
what i wanna do is to revrse all the words in a file but i have figured out that if the word
is longer than 1000 characters the progie will crash ,i wanna know if there is a way to solve this problemo?
------------------------------------------------------------------------------------------------------------------------
This message will self destruct in 5 seconds starting from ....
-
firstly, i have never used strrev().
the cause of this problem might be due to how you are reading in the file. set up a function or something to read in the file. or more specifically, each word in the file into a string or character array that holds a maximum of 1000 characters, and if it exceeds this, store it somewhere temp, and continue reading in the word. reverse them individually and stick them back together, send to a stream. you will probably have to use loops somewhere in for this to work. why can you not use loops in this program?
-
Can't you just read the length of the string and do it in sections that are reversible. it could be done w/o loops, although using them would be easier. I'm don't know c/c++ commands, but here's what I'm thinking
- Get the length of the string
myStringLen = Len(mylongstring)
- Set your "section" size... something that won't freeze (ie 500)
mySectionSize = 500
- Get a section to reverse
LocationInString=myStringLen
If LocationInString > 500 Then
myNewString = myNewString + mid(string,LocationInString-MySectionSize+1,LocationInString)
LocationInString = LocationInString-MySectionSize
Else
myNewString = myNewString + mid(string,1,LocationInString)
End if
'''''' (again, don't know the actual commands, just showing what I'm thinking)
'''''' If the string length is 1250, this should pull from 751-1250 and strore it in myNewString
Repeat the same code as many times as you might theoretically need (this is where a loop would be better)
If LocationInString > 500 Then
myNewString = myNewString + mid(string,LocationInString-MySectionSize+1,LocationInString)
LocationInString = LocationInString-MySectionSize
Else
myNewString = myNewString + mid(string,1,LocationInString)
End if
Don't know if that makes sense or if it's flawed thinking. Been a while since I've been in the trenches :-)
oops, forgot the strrev()....
myNewString = myNewString + mid(string,1,LocationInString)
should be
myNewString = myNewString + strrev(mid(string,1,LocationInString))
-
Re: reversing a string!
Quote:
Originally posted here by black_death
(c/c++)
is it possible to reverse a string with strrev when the string is longer than 1000 characters?
please note that i only want to use strrev() and no loops or anything else!
------------------------------------------------------------------------------------------------------------------------
This message will self destruct in 5 seconds starting from ....
I would probably use an array - have you tried that with strrev? Also, why don't you want to use a loop?
Just found this - it uses a char array. I don't know if it will work with a string of 1000 chars, though.
strrev code