| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1175 人关注过本帖
标题:为什么函数体一直提示错误,就swap和exchange
只看楼主 加入收藏
过五矿
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2015-10-29
结帖率:57.14%
收藏
已结贴  问题点数:10 回复次数:7 
为什么函数体一直提示错误,就swap和exchange
#include <stdio.h>
#include<string.h>
#include <stdlib.h>
int stu_ID[3]={1001,1002,1003};
int stu_class[3]={11,22,11};
float stu_score [3][3]={{99.5,88.5,89.5},{77.9,56.5,87.5},{92.5,99.0,60.5}};
char stu_name[3][10]={"zhang","li","wang"};
float stu_sum[3];

int main()
{
    int i,j;
    void add(float b[3][3]);
    void sort(float a[3]);
    void exchange(int,int);
    void swap(int,int);

    add(stu_score);
    sort(stu_sum);

    for(i=0;i<3;i++)
    {printf("%d,%d,%s,",stu_ID[i],stu_class[i],stu_name[i]);
          for(j=0;j<3;j++)
            {printf("%3.1f,",stu_score[i][j]); }
    printf("%4.1f\n",stu_sum[i]);
    }
return  0;
}

void add(float b[3][3])
  {   int i,j;
      float stu_sum[3]={0};
      for(i=0;i<3;i++)
        for(j=0;j<3;j++)
          {stu_sum[i]+=b[i][j];}
  }

void  sort(float a[3])
  {
  int i,j;
  for(i=0;i<2;i++)
    for(j=0;j<2-i;j++)
  {
      if(a[j]<a[j+1])
       {
        exchange(j,j+1);
        swap(j,j+1);
       }
  }

  }
void exchange(int i,int j)
{
    int t;
    float temp;
    t=stu_class[i];stu_class[i]=stu_class[j];stu_class[j]=t;
    t=stu_ID[i];stu_ID[i]=stu_ID[j];stu_ID[j]=t;
    for(t=0;t<3;t++)
    {temp=stu_score[i][t];stu_score[i][t]=stu_score[j][t];stu_score[j][t]=temp;}
}
void swap(int i,int j)
{
    char n[10];
    strcpy(n,stu_name[i]);strcpy(stu_name[i],stu_name[i+1]);strcpy(stu_name[i+1],n);
}
搜索更多相关主题的帖子: zhang include exchange 
2015-10-29 13:08
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:4 
应该将编译器给出的错误信息贴出来如
exchange(j,j+1); 这一句报 'exchange': identifier not found
swap(j,j+1); 这一句报 'swap': identifier not found
2015-10-29 13:55
qq1625127317
Rank: 6Rank: 6
等 级:侠之大者
威 望:1
帖 子:185
专家分:450
注 册:2015-9-3
收藏
得分:4 
把主函数里的函数声明放在主函数前面就行了

静坐常思己过,闲谈莫论人非
2015-10-29 14:01
过五矿
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2015-10-29
收藏
得分:0 
回复 2楼 rjsp

error: incompatible implicit declaration of function "excchange"
error:incompatible implicit declaration of function "swap"

code block 提醒的错误。
2015-10-29 14:58
过五矿
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2015-10-29
收藏
得分:0 
回复 3楼 qq1625127317
按照指示改后,虽然没有提醒错误,然而程序根本就没有运行,直接跳过函数操作输出了。数据都没有变化,为什么,求解
2015-10-29 15:01
xxhuan_2003
Rank: 1
等 级:新手上路
威 望:1
帖 子:10
专家分:6
注 册:2015-10-27
收藏
得分:4 
void add(float b[3][3])内将  float stu_sum[3]={0};去掉试试
2015-10-30 22:54
xxhuan_2003
Rank: 1
等 级:新手上路
威 望:1
帖 子:10
专家分:6
注 册:2015-10-27
收藏
得分:0 
  在函数体内,如果局部变量和全局变量同名,使用的是局部变量,而不是全局变量,所以,  float stu_sum[3]={0};会使得你用的变量是局部变量,函数结束后丢失!!而全局变量不会产生变化
2015-10-30 22:56
过五矿
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2015-10-29
收藏
得分:0 
回复 7楼 xxhuan_2003
谢谢,去掉后果然对了
2015-10-31 13:26
快速回复:为什么函数体一直提示错误,就swap和exchange
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017617 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved