问题描述:
c语言,逆序输出一句话中的单词入,I am a student输出student a am
我写的代码如下,没错误,但编译器不通过
#include "stdafx.h"
#include "string.h"
char *fun(char *array)
{
char *str=NULL;
int n=strlen(array);
for(int i=n-1;i>=0;i--)
{
int temp=i+1;
if(i==0)
{
while(array[i]!=' ')
{
*str++=array[i++];
}
}
if(array[i]==' ')
{
while((array[temp]!='\0')||(array[temp]!=' '))
{
*str++=array[temp++];
}
}
}
return str;
}
void main()
{
char a[]="I am a student";
printf("%s ",fun(a));
}
我写的代码如下,没错误,但编译器不通过
#include "stdafx.h"
#include "string.h"
char *fun(char *array)
{
char *str=NULL;
int n=strlen(array);
for(int i=n-1;i>=0;i--)
{
int temp=i+1;
if(i==0)
{
while(array[i]!=' ')
{
*str++=array[i++];
}
}
if(array[i]==' ')
{
while((array[temp]!='\0')||(array[temp]!=' '))
{
*str++=array[temp++];
}
}
}
return str;
}
void main()
{
char a[]="I am a student";
printf("%s ",fun(a));
}
问题解答:
我来补答展开全文阅读