[Interview Questions] [C language] Write a program to realize the reverse order of the string, and there can be spaces

The string is in reverse order, there can be spaces, C language

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>//assert的头文件
void reverse(char* str)
{
    
    
	assert(str);//注意审题,可以有空格
	int len = strlen(str);

	char*left = str;
	char*right=str+len-1;

	while (left < right)
	{
    
    
		char tmp = *left;
		*left = *right;
		*right = tmp;
		left++;
		right--;
	}
	
}
int main()
{
    
    
	char arr[256] = {
    
     0 };
	gets(arr);
	reverse(arr);
	printf("逆序后:%s\n", arr);
	system("pause");
	return 0;
}

Insert picture description here
In the process of writing code, we must follow the requirements of the topic and meet all the conditions.

Guess you like

Origin blog.csdn.net/weixin_54748281/article/details/114158791