#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char s[100];
printf("请输入要逆序的字符串!\n");
scanf("%s",s);
int i;
char temp;
for(i = 0;i <= strlen(s)/2-1 ; i++)
{
temp = s[i];
s[i] = s[strlen(s)-1-i];
s[strlen(s)-1-i] = temp;
}
printf("逆序:\n");
printf("%s\n",s);
}
//用指针,建立头尾指针
void daoxu(char *s)
{
char *head = s;
char *end = s;
char *p = s;
char temp;
while(*p != '\0')
{
p++;
}
end = p-1;
while(head < end)
{
temp = *head;
*head = *end;
*end = temp;
head++;
end--;
}//逆序完成
}
#include <stdlib.h>
#include <string.h>
int main()
{
char s[100];
printf("请输入要逆序的字符串!\n");
scanf("%s",s);
int i;
char temp;
for(i = 0;i <= strlen(s)/2-1 ; i++)
{
temp = s[i];
s[i] = s[strlen(s)-1-i];
s[strlen(s)-1-i] = temp;
}
printf("逆序:\n");
printf("%s\n",s);
}
//用指针,建立头尾指针
void daoxu(char *s)
{
char *head = s;
char *end = s;
char *p = s;
char temp;
while(*p != '\0')
{
p++;
}
end = p-1;
while(head < end)
{
temp = *head;
*head = *end;
*end = temp;
head++;
end--;
}//逆序完成
}