reversing a string!
Results 1 to 6 of 6

Thread: reversing a string!

  1. #1
    Member
    Join Date
    Sep 2002
    Posts
    98

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

  2. #2
    Member
    Join Date
    Aug 2001
    Posts
    90
    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.
    I blame you cos my mind is not my own, so don't blame me if I trespass in your zone!

  3. #3
    Member
    Join Date
    Sep 2002
    Posts
    98
    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 ....

  4. #4
    Senior Member
    Join Date
    Jun 2002
    Posts
    394
    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?
    Hmm...theres something a little peculiar here. Oh i see what it is! the sentence is talking about itself! do you see that? what do you mean? sentences can\'t talk! No, but they REFER to things, and this one refers directly-unambigeously-unmistakably-to the very sentence which it is!

  5. #5
    Senior Member
    Join Date
    Nov 2002
    Posts
    174
    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))
    Mike Reilly
    bluebeard96@yahoo.com

  6. #6
    () \/V |\| 3 |) |3\/ |\|3G47|\/3
    Join Date
    Sep 2002
    Posts
    744

    Re: reversing a string!

    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

    Go Finland!
    Deviant Gallery

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •