从键盘输入一个字符串,使其反序存放,在主函数中输入、输出该字符,编写一个函数
展开全部
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char *reverseString(char *str)
{
char *h, *t;
char mid;
int i = 0;
h = str;
t = str;
while(*t != '\0')
{
t++;
}
t = t-1;
while(1)
{
if(h >= t)
{
break;
}
mid = *h;
*h = *t;
*t = mid;
h++;
t--;
}
return str;
}
void main()
{
char str[100];
printf("请输入要处理点字符串:");
gets(str);
printf("原始字符串为:%s\n",str);
printf("翻转字符串为:%s\n",reverseString(str));
}
#include<string.h>
#include<stdlib.h>
char *reverseString(char *str)
{
char *h, *t;
char mid;
int i = 0;
h = str;
t = str;
while(*t != '\0')
{
t++;
}
t = t-1;
while(1)
{
if(h >= t)
{
break;
}
mid = *h;
*h = *t;
*t = mid;
h++;
t--;
}
return str;
}
void main()
{
char str[100];
printf("请输入要处理点字符串:");
gets(str);
printf("原始字符串为:%s\n",str);
printf("翻转字符串为:%s\n",reverseString(str));
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-12-16
展开全部
void reverse(char *s)
{
char temp;
int count = 0;
while(s[count] != '\0')
count++;
count--;
for (int i = 0; i <= count/2; i++){
temp = s[i];
s[i] = s[count-i];
s[count-i] = temp;
}
s[++count] = '\0';
}
int main()
{
char s[100];
scanf("%s", &s);
reverse(s);
puts(s);
return 0;
}
{
char temp;
int count = 0;
while(s[count] != '\0')
count++;
count--;
for (int i = 0; i <= count/2; i++){
temp = s[i];
s[i] = s[count-i];
s[count-i] = temp;
}
s[++count] = '\0';
}
int main()
{
char s[100];
scanf("%s", &s);
reverse(s);
puts(s);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询