C 练习实例35
C 语言教程
· 2019-02-21 20:41:56
题目:字符串反转,如将字符串 "www.codercto.com" 反转为 "moc.boonur.www"。
程序分析:无。
实例
// Created by www.codercto.com on 15/11/9.
// Copyright © 2015年 码农教程. All rights reserved.
//
#include <stdio.h>
void reverse(char* s)
{
// 获取字符串长度
int len = 0;
char* p = s;
while (*p != 0)
{
len++;
p++;
}
// 交换 ...
int i = 0;
char c;
while (i <= len / 2 - 1)
{
c = *(s + i);
*(s + i) = *(s + len - 1 - i);
*(s + len - 1 - i) = c;
i++;
}
}
int main()
{
char s[] = "www.codercto.com";
printf("'%s' =>\n", s);
reverse(s); // 反转字符串
printf("'%s'\n", s);
return 0;
}
以上实例输出结果为:
'www.codercto.com' => 'moc.boonur.www'
点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html
Non-Obvious
Rohit Bhargava / Ideapress Publishing / 2015-3-29 / USD 24.95
What do Disney, Bollywood, and The Batkid teach us about how to create celebrity experiences for our audiences? How can a vending-machine inspire world peace? Can being imperfect make your business mo......一起来看看 《Non-Obvious》 这本书的介绍吧!