黑马程序员技术交流社区

标题: 将字符串逆序存放并输出 [打印本页]

作者: flymanshow    时间: 2015-7-17 22:45
标题: 将字符串逆序存放并输出
例如当字符串为“this is a program”输出为“margorp a si siht”
作者: 慕名黑马生    时间: 2015-7-18 00:26
for循环,从最后的字符开始输出
作者: FreshMAN15    时间: 2015-7-18 00:33
void String(char str[],int len)
{
int i=0,j=len-1;
char temp;
while(i<j)
{
temp=*str[i];
*str[i]=*str[j];
*str[j]=temp;
}

printf("%s",str);

}

作者: 294250051    时间: 2015-7-18 11:39
#include "stdio.h"
#include "string.h"
int main()
{
    char s[]="this is a program";
    char *p=s+strlen(s);
    for (; p>=s; p--) {
        printf("%c",*p);
    }
    return 0;
}




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2