本程序在Turbo C 2.0下编译通过,在使用VC.NET和Dev C++ 4.9 进行编译的时候提示写冲突。
#include <stdio.h>
char * mystrcat(char * dst,const char *src)
{
char *start = dst;
while(*dst)dst++;
while(*dst++ = *src++);
return start;
}
char * wordrev(char *str)
{
char *start,*p,*pp;
p=(char *)str;
pp =p;
while(*p) p++;
while(*p != ' ') p--;
start = p+1;
*p = '/0';
while(p >= pp)
{
while(*p != ' ')
{
p--;
if(p == pp)
{
mystrcat(start," ");
mystrcat(start,p);
break;
}
}
if(p != pp)
{
mystrcat(start,p);
*p = '/0';
}
}
return start;
}
void main(void)
{
char * str = "I am a student";
puts(wordrev(str));
getchar();
}
本文介绍了一个用于反转字符串中单词顺序的C语言程序实现。该程序定义了两个函数:mystrcat用于字符串连接,wordrev用于单词反转。通过主函数演示了如何使用wordrev函数来反转字符串Iamastudent中的单词顺序。

368

被折叠的 条评论
为什么被折叠?



