Thread: String Reversal - No temp string - C language

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    1

    Unhappy String Reversal - No temp string - C language

    Please give me a peice of code which will reverse the string with out using temporary string.

    Given string: "Car is black in colour"
    output: "colour in black is Car"

    Please help me by giving the code preferably in C.

    Thanks in advance,
    murali

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    So you want to reverse the words not the string? Why don't you write it with a temporary string and then figure out hwo you can remove it instead of us dong all the work?

  3. #3
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    Please help me by giving the code preferably in C.
    That's not gonna happen. Sorry, but this reeks of homework and if we gave you the code then you wouldn't learn anything. But here's a hint: Reverse each word, then reverse the whole string. You can do an in-place reversal by swapping characters from the outside in.
    Just because I don't care doesn't mean I don't understand.

  4. #4
    Registered User
    Join Date
    Nov 2004
    Location
    USA
    Posts
    516
    sniff....sniff....i smell homework.
    Getting back to your question, you should learn that a string is represented as a char array...now about reversing the string, i understand bout not using the temp string...u can just allocate some memory using malloc and then free it.I leave it up to u to think how to actually reverse the string.Dont expect to get code written from someone over here..programming is all about doing IT on your own.
    Code:
    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Sorry we won't be doing your homework for you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  2. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. Help with my program
    By duty11694 in forum C Programming
    Replies: 2
    Last Post: 11-24-2002, 05:54 PM