1. 程式人生 > >c++寫一個函式,實現輸入一個字串,將其中的字元按逆序輸出

c++寫一個函式,實現輸入一個字串,將其中的字元按逆序輸出

#include "stdafx.h"
#include <iostream>
#include <string.h>
using namespace std;
#define N 20

int _tmain(int argc, _TCHAR* argv[])
{
	char str[N];
	void string_reverse(char s[],int n);
	cout<<"請輸入一串字串:"<<endl;
	gets_s(str);
	cout<<endl;
	cout<<"倒序後:"<<endl;
	string_reverse(str,N);
	cout<<endl;
	return 0;
}
//實現輸入一個字串,將其中的字元按逆序輸出的函式
void string_reverse(char s[],int n)
{
	int i;
	for(i=strlen(s)-1;i>=0;i--)
		cout<<s[i];

}