[求助]请看看这个关于数字查找的问题,关于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);
}