字符串反轉

#include<iostream>
#include<malloc.h>
#include<string.h>
using namespace std;
int convert(string s)
{
	char c[10][20];
	int i=0;
	int j=0;
	int k=0;
	while(s[i]!='\0')
	{
		if(s[i]!=' ')
		{
			c[j][k]=s[i];
			k++;
			i++;
		}
		else
		{
			c[j][k]='\0';
		    j++;
		    k=0;
		    i++;
		}
	}
	c[j][k]='\0';
	for(k=j;k>=0;k--)
		cout<<c[k]<<' ';
	return 0;
}
int main()
{
	string s="hello. world!";
	convert(s);
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章