void main1()
{
char buf[100] = "jefyxingyi";
int len = 0;
while (buf[len++]);
len--;
{
char buf[100] = "jefyxingyi";
int len = 0;
while (buf[len++]);
len--;
int min = 0;
int max = len - 1;
while (min < max)
{
int temp = buf[min];
buf[min] = buf[max];
buf[max] = temp;
min++;
max--;
}
int max = len - 1;
while (min < max)
{
int temp = buf[min];
buf[min] = buf[max];
buf[max] = temp;
min++;
max--;
}
printf("%s
", buf);
system("pause");
}
//含有汉字的字符串逆序
void main2()
{
char buf[100] = "你好世界";
int len = 0;
while (buf[len++]);
len--;
{
char buf[100] = "你好世界";
int len = 0;
while (buf[len++]);
len--;
int min = 0;
int max = len - 1;
while (min <max)
{
int temp = buf[min];
buf[min] = buf[max -1];
buf[max -1] = temp;
int max = len - 1;
while (min <max)
{
int temp = buf[min];
buf[min] = buf[max -1];
buf[max -1] = temp;
temp= buf[min + 1];
buf[min + 1] = buf[max];
buf[max] = temp;
buf[min + 1] = buf[max];
buf[max] = temp;
min = min + 2;
max = max - 2;
}
printf("%s ", buf);
system("pause");
max = max - 2;
}
printf("%s ", buf);
system("pause");
}
//统计字符个数
void main()
{
char buf[100] = "ab你好";
int i = 0;
int len = 0;
while (buf[i])
{
if (buf[i]<0)
{
i++;
}
i++;
len++;
}
printf("%d", len);
system("pause");
}
void main()
{
char buf[100] = "ab你好";
int i = 0;
int len = 0;
while (buf[i])
{
if (buf[i]<0)
{
i++;
}
i++;
len++;
}
printf("%d", len);
system("pause");
}
//去掉尾部空格
void main04()
{
char buf[100] = "jefynihao jefy ";
int len = 0;
while (buf[len++]);
len--;
void main04()
{
char buf[100] = "jefynihao jefy ";
int len = 0;
while (buf[len++]);
len--;
for (int i = len - 1; i >= 0;i--)
{
if (buf[i]!=' ')
{
buf[i+1] = ' ';
break;
}
}
{
if (buf[i]!=' ')
{
buf[i+1] = ' ';
break;
}
}
printf("%s", buf);
system("pause");
}
//去掉字符串前面空格
void main()
{
char buf[100] = " jefy";
int len = 0;
while (buf[len++] ==' ')
;
len--;
int i = len;
while (buf[i])
{
buf[i - len] = buf[i];
i++;
}
buf[i - len] = 0;
printf("%s ", buf);
system("pause");
}
//去掉字符串前面空格
void main()
{
char buf[100] = " jefy";
int len = 0;
while (buf[len++] ==' ')
;
len--;
int i = len;
while (buf[i])
{
buf[i - len] = buf[i];
i++;
}
buf[i - len] = 0;
printf("%s ", buf);
system("pause");
}