| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 913 人关注过本帖
标题:[求助]函数返回指针地址问题,高手看看
只看楼主 加入收藏
Javal
Rank: 1
等 级:新手上路
威 望:1
帖 子:108
专家分:0
注 册:2006-5-7
收藏
得分:0 

帮你改了下,在C-FREE 3.5下运行通过
#include<stdio.h>
#include<conio.h>

struct worklist
{
int num;
char name[10];
}worker[10] = {{2,"wang"},{1,"li"},{3,"zhang"},{7,"yang"},{8,"sun"},{5,"you"},
{4,"miao"},{9,"wu"},{10,"han"},{6,"zhao"}};
void xuanze()
{
int i, j, k;
struct worklist temp;

for (i = 0; i < 9; i++)
{
k = i;

for (j = k+1; j < 10; j++)
{
if (worker[k].num > worker[j].num)
{
k = j;
}
}
if(k != i)
{
temp = worker[i];
worker[i] = worker[k];
worker[k] = temp;
}
}
}
char *find(int n)
{
int low, mid, high, i;

for(low = 0, high = 9; high >= low; )
{
mid = (low + high) / 2;
if(worker[n-1].num == worker[mid].num)
{
return worker[mid].name;
//break; //已经return了,break就没用
}
else if(worker[n-1].num > worker[mid].num)
{
low=mid+1;
}
else
{
high=mid-1;
}
}
}
void maopao()
{
int i,j;
struct worklist temp;

for(i = 0; i < 9; i++)
{
for(j = i; j < 9; j++)
{
if(worker[j].num > worker[j+1].num)
{
temp = worker[j];
worker[j] = worker[j+1];
worker[j+1] = temp;
}
}
}
}

int main(void)
{
int i, num;
char *p;
//char b[30]; //这个数组没用吧?

printf("打印初始序列:\n");
for(i = 0; i < 10; i++)
{
printf("%-2d %-4s\n", worker[i].num, worker[i].name); // 加了打印格式,用于对齐
}

//maopao();
xuanze();
printf("打印排序后的序列:\n");
for(i = 0; i < 10; i++)
{
printf("%-2d %-4s\n",worker[i].num,worker[i].name);
}

printf("Please Input a number:");
scanf("%d", &num);
p = find(num);
printf("%s\n", p);
getch();

return 0;
}

[此贴子已经被作者于2007-4-12 14:53:09编辑过]


猝然临之而不惊,无故加之而不怒 /?spaced" target="_blank">Linux C资料
2007-04-12 14:51
YANGDAN123
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2007-1-16
收藏
得分:0 

好的,谢谢楼上的


我将用我全部的时间去寻找我生命和灵魂的唯一伴侣,得之,我幸,不得,我命。
2007-04-19 11:44
快速回复:[求助]函数返回指针地址问题,高手看看
数据加载中...
 
   



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

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