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

查看所有标签

Web Analytics

Web Analytics

Avinash Kaushik / Sybex / 2007-6-5 / USD 29.99

在线阅读本书 Written by an in-the-trenches practitioner, this step-by-step guide shows you how to implement a successful Web analytics strategy. Web analytics expert Avinash Kaushik, in his thought-p......一起来看看 《Web Analytics》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具