问题遇到的现象和发生背景
头歌里运行报错
问题相关代码,请勿粘贴截图
#include <stdio.h>
#include <string.h>
#define N 4 /* 网址表大小 */
void sort(struct web webs[],int n);
struct web /* 设计表示网址的结构 */
{
/********** Begin **********/
char srt[100];
char name[100];
char website[100];
/********** End **********/
};
struct web webs[N];
struct web temp;
int main()
{
/********** Begin **********/
for(int i=0;i<N;i++){
scanf("%s %s %s",&webs[i].srt,&webs[i].name,&webs[i].website);
}
char get[20];
scanf("%s",get);
sort(webs,N);
for(int i=0;i<N;i++){
printf("%s %s %s\n",webs[i].srt,webs[i].name,webs[i].website);
}
int len=strlen(get);
int flag=0;
for(int k=0;k<N;k++){
if(strncmp(get,webs[k].srt,len)==0){
flag=1;
printf("%s",webs[k].website);
}
}
if(flag==0) printf("未找到搜寻的网址");
/********** End **********/
return 0;
}
void sort(struct web webs[],int n)
{
/********** Begin **********/
for(int i=0;i<N-1;i++){
for(int j=0;j<N-1-i;j++){
if(strcmp(webs[j].srt,webs[j+1].srt)>0){
temp=webs[j+1];
webs[j+1]=webs[j];
webs[j]=temp;
}
}
}
/********** End **********/
}
运行结果及报错内容
0/3
src/step3/Step3_main.c:4:22: error: array type has incomplete element type ‘struct web’
void sort(struct web webs[],int n);
^~~~
src/step3/Step3_main.c:4:18: warning: ‘struct web’ declared inside parameter list will not be visible outside of this definition or declaration
void sort(struct web webs[],int n);
^~~
src/step3/Step3_main.c: In function ‘main’:
src/step3/Step3_main.c:29:7: error: type of formal parameter 1 is incomplete
sort(webs,N);
^~~~