Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Language Examples - Reverse a String

C Language Examples - Reverse a String

C Language Examples C Language Examples

Use recursion to reverse a string.

Example - String reversal

#include

<

stdio.h

void

reverseSentence

(

)

;

int

main

(

)

{

printf

(

"

Enter a string:

"

)

;

reverseSentence

(

)

;

return

0

;

}

void

reverseSentence

(

)

{

char

c

;

scanf

(

"

%c

"

, &

c

)

;

if

(

c

!= '\

n

'

)

{

reverseSentence

(

)

;

printf

(

"

%c

"

,

c

)

;

}

}

The output is:



输入一个字符串: runoob

boonur

C Language Examples C Language Examples