C language: string output in reverse order

It is almost the same as the previous digital reverse output, as well as word reversal and so on.

To facilitate analysis, the analysis part is written into the code...

Code display:

#include <stdio.h>
#include <string.h>

void ReverseSTring(char str[]);


int main()
{
    
    
	char str[200]={
    
    0};//初始化
	printf("input a string: ");
	gets(str);

	ReverseSTring(str);

	puts("output:");
	puts(str);

	return 0;
}

void ReverseSTring(char str[])
{
    
    
	char ch;
	int i, j;
	j = strlen(str) - 1;//这里标记了该输入的字符串最后一位
	for (i = 0; i < j; i++, j--)//循环做调换。
	{
    
    
		ch = str[i];
		str[i] = str[j];
		str[j] = ch;
	}
}


The algorithm is simple and easy to understand...

Guess you like

Origin blog.csdn.net/yooppa/article/details/114642447