注册 登录
编程论坛 C++教室

请高手解决一下这个程序得错误 错在哪些地方 谢谢

dingyongq 发布于 2008-10-18 18:44, 690 次点击
这个程序 放到C++上调试  出现一些错误  自己不会改
请高手帮下忙  讲解一下 谢谢了
#include <stdio.h>
struct sqlist
{
    int slem[100];
    int len;
};
int search_sqlist(sqlist v,int b)
{
    for(int i=1; i<=v.len;i++)
        if(v.len[i-1]==b)
            return i;
} return 0;

void main()
{
    sqlist w;
    w.elem[0]=1;w.elem[1]=2;w.elem[2]=4;w.elen[3]=9;w.elen[4]=8;w.len[5];
    int bb ==9;
    int address=search_sqlist(w,bb);
    if(address==0)
        printf("没有找到");
    else
        printf("该元素得位置为%d\n",address);
}
6 回复
#2
个人爱好2008-10-18 19:59
我改了了好多地方
你看看还可以
#include <stdio.h>
struct sqlist
{
    int slem[100];
    int len;
};
int search_sqlist(sqlist v,int b)
{
    for(int i=1; i<=v.len;i++){

        if(v.slem[i-1]==b)
            return i;}
         return 0;
}

void main()
{
    sqlist w;
    w.slem[0]=1;
    w.slem[1]=2;
    w.slem[2]=4;
    w.slem[3]=9;
    w.slem[4]=8;
    w.len=5;
    int bb=9;
    int address=search_sqlist(w,bb);
    if(address==0)
        printf("没有找到");
    else
        printf("该元素得位置为%d\n",address);
}
我运行了,是可以的!
#3
dingyongq2008-10-20 08:53
回复 2# 个人爱好 的帖子
哈哈   太感谢你了!! 我要看看我到底都错哪了  
#4
lionmusicyj2008-10-20 09:21
楼主啊~!!!!太粗心了哦~!变量都自己写错了~!自己看看楼上那位和我跟你的该的变量名~!还有return 0你写在子函数外面是啥意思啊?一般只是在 mian 函数中才用的,还有所有用双杠标出来的都是你错的地方~!
#include <stdio.h>
#include <iostream>
using namespace std;
struct sqlist
{
    int slem[100];
    int len;
};
int search_sqlist(sqlist v,int b)
{
    for(int i=1; i<=v.len;i++)
       if(v.slem[i-1]==b)// if(v.len[i-1]==b)
            return i;
} //return 0;

int main()
{
    sqlist w;
    w.slem[0]=1;
    w.slem[1]=2;
    w.slem[2]=4;
    w.slem[3]=9;
    w.slem[4]=8;
    w.len=5;//w.len[5];
    int bb=9;//int bb ==9;
    int address=search_sqlist(w,bb);
    if(address==0)
        printf("没有找到");
    else
        printf("该元素得位置为%d\n",address);
    system("pause");
    return 0;
}
#5
choco10242008-10-20 23:09
打扰下,楼上那位后来写的 system("pause");这句是啥意思啊,有啥作用呀?我一直没见过。
#6
asd67918682008-10-21 08:30
看了2楼的
应该是slem 和 elen的问题吧
#7
lionmusicyj2008-10-21 10:37
那个是让系统暂停的界面,呵呵~!
试一下就知道了~!
1