| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 743 人关注过本帖
标题:[求助]请看看这个关于数字查找的问题,关于array,rownumber
只看楼主 加入收藏
brokensea
Rank: 1
等 级:新手上路
帖 子:63
专家分:0
注 册:2007-10-14
收藏
 问题点数:0 回复次数:1 
[求助]请看看这个关于数字查找的问题,关于array,rownumber
这个哪里错了,可以指点下吗?
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "myheader.h"
/*maximum number of rows of data was can store in records[]*/
#define NUMROWS 10
/*array of records we are processing*/
struct myrec records [NUMROWS];
/*get the data for one row of our table grtumts;
rownumber number of the row ir records [] array to fill*/
void get_a_row(int rownumber){
   char tbuf[20];
    int tlen;
printf("Enter name");
fgets(records[rownumber].name,80,stdin);
/*remove trailing nwe line form name string i there is one*/
tlen=strlen(records[rownumber].name);
if(records[rownumber].name[tlen-1]=='\n'){
  records[rownumber].name[tlen-1]=0;
}
printf("Enter age:");
/*we have to use fgets(),not scanf(),since cygwin is busted*/
fgets(tbuf,80,stdin);
sscanf(tbuf,"%d",&records[rownumber].age);
return;
}
/*shwo the data for one row of our table arguments: rownumber numberof the row in records[]array to fill*/
void show_a_row(int rownumber){
printf("Name:%s\n",records[rownumber].name);
printf("Age:%d\n",records[rownumber].age);
return;
}
/*sort the data in the rows of data in the array*/
void sort_name(int numrows){
int i,j;
char thempname[80];
for(i=0;i<numrows;++i){
for(j=0;j<numrows-1;++j){
if(strcmp(records[j].name,records[j+1].name)>0){
strcpy (tempname,records[j].name);
tempage=records[j].age;
strcpy(records[j].name,records[j+1].name);
records[]j.age=records[j+1].age;
strcpy(records[j+1].name,tempname);
records[j].age=records[j+1].age;
strcpy(records[j+1].name,tempname);
record[j+1].age=tempage;
   }
  }
 }
return;
}
int main(void){
    int/;
/*get the data*/
forci=;i<5;++i){
get_a_row(i);
}
/*sort the data based on name*/
sort_name[5];
/*display the sorted data*/
forci=0;i<5;++i){
show_a_row(i);
}
return(EXIT_SUCCESS);
}
搜索更多相关主题的帖子: array rownumber 数字 
2008-11-04 22:22
brokensea
Rank: 1
等 级:新手上路
帖 子:63
专家分:0
注 册:2007-10-14
收藏
得分:0 
Oh I am very sad why none help me~
please somebody give me some help
I have stop here very longtime

brokensea~~
Just try try try and try
2008-12-14 13:30
快速回复:[求助]请看看这个关于数字查找的问题,关于array,rownumber
数据加载中...
 
   



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

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