求高手认真读读我的程序,帮忙看看错误在哪···~~编译的时候我晕了~~

我的程序如下~~
#include<stdio.h>
#include<string.h>
float fun(int,char **);
int main()
{
char ss[10][87];int numz=0;float k;
do
{
printf("输入第%d个字符串:\n",numz);
gets(ss[numz]);
numz+=1;
}while(*ss[numz-1]!="****");
numz-=2;
k=fun(numz,ss);
printf("地址是:%f\n",k);
return 0;
}
float fun(int num,char **max)
{
int i;
char s[10][87];
s[0]=*(max);
for(i=0;i<=num-1;i++)
{
if(strlen(s)<strlen(*(max+i+1)))
s[0]=*(max+i+1);
}
printf("最长的字符串是:\n");
puts(s[0]);
*max=s[0];
return (max);
}
--------------------Configuration: lianan - Win32 Debug--------------------
Compiling...
lianan.c
C:\Documents and Settings\Administrator\桌面\编程\lianan.c(12) : warning C4047: '!=' : 'int ' differs in levels of indirection from 'char [5]'
C:\Documents and Settings\Administrator\桌面\编程\lianan.c(14) : warning C4047: 'function' : 'char ** ' differs in levels of indirection from 'char [10][87]'
C:\Documents and Settings\Administrator\桌面\编程\lianan.c(14) : warning C4024: 'fun' : different types for formal and actual parameter 2
C:\Documents and Settings\Administrator\桌面\编程\lianan.c(22) : error C2106: '=' : left operand must be l-value
C:\Documents and Settings\Administrator\桌面\编程\lianan.c(25) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'char [10][87]'
C:\Documents and Settings\Administrator\桌面\编程\lianan.c(25) : warning C4024: 'strlen' : different types for formal and actual parameter 1
C:\Documents and Settings\Administrator\桌面\编程\lianan.c(26) : error C2106: '=' : left operand must be l-value
C:\Documents and Settings\Administrator\桌面\编程\lianan.c(31) : error C2115: 'return' : incompatible types
Error executing cl.exe.

守着星空守着你
浏览 133回答 3
3回答

斯蒂芬大帝

#include<stdio.h>#include<string.h>char* fun(int,char max[][87]);int main(){char ss[10][87];int numz=0;char* k;do{printf("输入第%d个字符串:\n",numz);gets(ss[numz]);numz+=1;}while(strcmp(ss[numz-1],"****")!=0);numz-=2;k=fun(numz,ss);printf("地址是:%X\n",k);return 0;}char* fun(int num, char max[][87]){int i;char *s;s=max[0];for(i=0;i<=num-1;i++){if(strlen(s)<strlen(max[i]))s = max[i];}printf("最长的字符串是:\n");puts(s);return (s);}改了一下 自己研究一下 呵呵!~ 没什么大问题PS:只随便调试了一下 不知道算法有无问题

牧羊人nacy

上面的都做出来了我就不做了,就分析下你错的地方:C:\Documents and Settings\Administrator\桌面\编程\lianan.c(12) : warning C4047: '!=' : 'int ' differs in levels of indirection from 'char [5]'错误语句:while(*ss[numz-1]!="****");解释:*ss[numz-1]代表一个地址不能等于字符串,可改为ss[numz-1]。C:\Documents and Settings\Administrator\桌面\编程\lianan.c(14) : warning C4047: 'function' : 'char ** ' differs in levels of indirection from 'char [10][87]'错误语句:k=fun(numz,ss);解释:ss为首地址指针。不能传给char ** ,只能传给char *。C:\Documents and Settings\Administrator\桌面\编程\lianan.c(22) : error C2106: '=' : left operand must be l-value错误语句:s[0]=*(max);解释s[0]为一个地址指针,不能存储。给数组赋值要用for(int i=0;i<max;i++){s[0][i]=*(max+i);}C:\Documents and Settings\Administrator\桌面\编程\lianan.c(25) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'char [10][87]'错误语句:if(strlen(s)<strlen(*(max+i+1)))解释:strlen需要传递一个char地址,s可改为s[0]。C:\Documents and Settings\Administrator\桌面\编程\lianan.c(31) : error C2115: 'return' : incompatible types错误语句:return (max);解释:函数返回值类型要更定义类型一样。max为char ** 类型,定义函数确为float。相同错误就不再说了。

扬帆大鱼

#include <stdio.h>#include <string.h>#define MAX_ROW 10#define MAX_COL 87/**********************************/char * fun(int num,char max[][MAX_COL]){int i;char *s;s=*(max);for(i=0;i<=num-1;i++){if(strlen(s)<strlen(max+i+1)) { s=max+i+1; }}printf("The longest string is :\n");puts(s);return s;}/***********************************/int main(){char ss[MAX_ROW][MAX_COL];int numz=0;char *k;do{printf("Please input string_%d :\n",numz);gets(ss[numz]);numz+=1;}while(strcmp(ss[numz-1],"****"));/* 字符串的比较不能直接用地址,但可以用strcmp函数。相同返回0,不同则返回1 */numz-=2;k=fun(numz,ss);printf("The address is 0x%x\n",k);getch();return 0;}
打开App,查看更多内容
随时随地看视频慕课网APP