0

以下の2つの機能があります。文字で表示されるようにコードを変更するにはどうすればよいですか?

たとえば、「A」を定義すると、Aで始まるAllRecordsのみが表示されます。

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) %s\n", 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
4

2 に答える 2

2

それはあなたが望むものですか?

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) %s\n", i, result);
  }
}
于 2012-08-05T09:53:54.720 に答える
2
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) %s\n", j, result);
        j++;
    }
  }
}
于 2012-08-05T09:54:03.740 に答える