c语言怎么把hello world倒着显示world hello

来源:百度知道 编辑:UC知道 时间:2024/06/30 23:22:54
能写个小程序么,谢谢

用VC写的
#include<stdio.h>
void main()
{
char str[50]={0};
int i=0;
gets(str);
while(str[i])i++;
while(i>=0)
{
i--;
putchar(str[i]);
}
printf("\n");
}

那直接写 printf("world hello"); 不就行了么? 请说明你的真正用意

#include <stdio.h>

int main(void)
{
char s[] = "hello world";
int i = 0;

while(s[i] != 32)
i++;

i++;
while(s[i] != '\0')
{
printf("%c", s[i]);
i++;
}
printf(" ");
i = 0;
while(s[i] != 32)
{
printf("%c", s[i]);
i++;
}

}

char str1[] = "hello world",str2[6],str3[6];
for(i=0;i<strLen(str1);i++){
if(str1[i]==' ') break;
str2[i]=str1[i];
}
for(i=i-1;i<strLen(str1)-i;i++){
str3[i]=s