#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <strings.h>
void swap(char *head,char *tail);
int main()
{
char str[64]={0},*p=NULL,*p2=NULL,*p3=NULL;
int len,i;
printf("输入一个字符串:");
gets(str);
len=strlen(str);
p=str;
p2=str+len-1;
p3=str;
swap(p,p2);
puts(str);
while(*p!='\0')
{
if(*p==' ')
{
swap(p3,p-1);
p3=p+1;
}
p++;
}
swap(p3,p2);
puts(str);
}
void swap(char *head,char *tail)
{
while(head<tail)
{
int temp=*tail;
*tail=*head;
*head=temp;
head++;
tail--;
}
}
C语言,将输入的字符串逆序输出(指针实现)
最新推荐文章于 2024-05-11 12:57:23 发布