please help me..
there anyone know how to reverse strings???
i really don't have idea for this..

please helps...

Recommended Answers

All 5 Replies

try this following code :

program Reverse_String;

 uses crt;

 const Elemen = 255;   {* Max character *}

 type S255     = string[Elemen];
      Stack = record
                   Input  : S255;
                   Tops : 0..Elemen
                 end;

 var  T       : Stack;  
      I       : integer;   
      StringInput : S255;     

  procedure AWALAN (var T : Stack);

  begin
    T.Tops := 0
  end;        

 
 procedure PUSH (var T : Stack; X : char);

 begin
   T.Tops := T.Tops + 1;
   T.Input[T.Tops] := X
 end;          {* PUSH *}

  function POP (var T : Stack) : char;

  begin
    POP := T.Input[T.Tops];
    T.Tops := T.Tops - 1
  end;         {* POP *}
 {*****************
  * Main program *
  *****************}
  begin
    clrscr;
    Awalan(T);
    writeln('Stack To reverse string');
    writeln('-------------------------------');
    writeln;

    {* String that it want to reverse*}
    write('Input any kind of Strings: ');
    readln(StringInput);

    clrscr;
    writeln('Original Strings:'); writeln(StringInput);

    writeln;writeln('Strings After Reverse:');

    {* push Input strings into Stack *}
    for I := 1 to length(StringInput) do
      PUSH (T, StringInput[I]);

    {* pop Stack Input until Input String reverse*}
    for I := 1 to length(StringInput) do
      write(POP(T));

    writeln
 end.
commented: what a wonderful code +1
commented: nice one... +1

wow...awesome..
thank you very much....
You are great person...:)

you're welcome friend :)

commented: welcome guy +1

There is a faster way too:

Exchange:
a := a xor b;
b:= a xor b;
a:= a xor b;

And then start from the sides, and exchange every byte (or two, depends how long a character is) till the midle.

thanks for info friend :)
i will try it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.