如何只按字母列出
How to list by letter only?
下面有两个函数。如何更改代码以便按字母显示?
例如,如果我定义"A",它将只显示以A.开头的所有记录
char* displayRecordContent (CountryRecordType ctryRec)
{
char * output;
output = ctryRec.Country;
return output;
}
// ====================================================================
void showAllRecords ()
{
int i=0;
char * result;
for (i=0; i<NoOfRecordsRead; i++)
{
result = displayRecordContent (globalCountryDataArray [i]);
printf ("(%d) %sn", i, result);
}
}
输出:
(0) Andorra
(1) United Arab Emirates
(2) Afghanistan
(3) Antigua and Barbuda
(4) Anguilla
(5) Albania
(6) Armenia
(7) Netherlands Antilles
(8) Angola
(9) Antarctica
void showAllRecords (char begin)
{
int i=0, j=0;
char * result;
for (i=0; i<NoOfRecordsRead; i++)
{
result = displayRecordContent (globalCountryDataArray [i]);
if (result[0] == begin) {
printf ("(%d) %sn", j, result);
j++;
}
}
}
这就是你想要的吗?
void showAllRecords ()
{
int i=0;
char * result;
for (i=0; i<NoOfRecordsRead; i++)
{
result = displayRecordContent (globalCountryDataArray [i]);
if(*result == 'A') // or other letter
printf ("(%d) %sn", i, result);
}
}
相关文章:
- 没有找到相关文章