rev_str.c
来自「《c与指针》书的代码 是我学习这本书时候敲出来的」· C语言 代码 · 共 32 行
C
32 行
/*
** Reverse the string contained in the argument.
*/
void
reverse_string( char *str )
{
char *last_char;
/*
** Set last_char to point to the last character in the
** string.
*/
for( last_char = str; *last_char != '\0'; last_char++ )
;
last_char--;
/*
** Interchange the characters that str and last_char point
** to, advance str and move last_char back one, and keep
** doing this until the two pointers meet or cross.
*/
while( str < last_char ){
char temp;
temp = *str;
*str++ = *last_char;
*last_char-- = temp;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?