哪位高人会呀,帮帮忙~~
编写函数 void fun(char* str),实现将str所指的字符串中最长的单词输出(在字符串中,单词之间用若干个空格分隔)。要求在main函数中输入字符串,调用fun函数。(必须用指针实现)
程序代码:#include<stdio.h>
#include <math.h>
char * fun(char *str,int *pint)
{
char *p = str;
int max = 0;
char *pmax = NULL;
int i = 0,j= 0,k = 0;
while(*p)
{
if(' ' != *p)
{
i++;
}
else
{
if(i>max)
{
pmax = p-i;
max = i;
*pint = max;
i = 0;
}
}
p++;
}
return pmax;
}
void main()
{
char a[] = "123 78974 561234567897 123456789";
int n = 0;
char *p = fun(a,&n);
p[n] = '\0';
printf("%s\n",p);
}
..............以后自己写写好不好










