0

私の質問についてはすでにあまりにも多くの質問があることを認識していますが、これまでに見た回答は、ポインター、int値になる関数の戻り値を想定しています。

と の 2 つの関数がvoid binarycheck(int encoding, product *curr[], int totalcurr)ありvoid search_show()ます。

binarycheck基本的に、指定encodingされた配列構造体から値を取得しますcurr(curr には、文字列と int の混合変数が含まれます)。その目的は、ビットごとの関数を介して各配列の curr をcurrチェックした後、配列を 3 つの主要なタイプと 5 つのサブクラスに分類することです。encoding

サブクラスは、 を形成するために使用された typedef 構造体に含まれていますcurr。お気に入り:

typedef struct nodebase{
    char name[254];
    char company_name[254];
    int encoding;
    double price;
    struct nodebase *next;
    struct nodebase *Class;
}product;

ここで、binarycheck関数を使用した後、void search_show基本的にユーザーに好みの 1) タイプ、2) サブクラスを尋ねvoid search_show、ユーザーが選択したタイプとサブクラスとして分類された製品を印刷します。

そのため、int (分類された各配列の存在をカウントするため) および配列 (データを分類するため) の形式のvoid search_show結果を使用する必要があります。void binarycheck

void binarycheckによって使用されるすべての変数をパラメーターとして配置することにより、「力ずく」の方法を考えてvoid search_showいましたが、変数が多すぎて追加できません。

すべての変数と最初の関数の結果を 2 番目の関数で "再利用" する方法を教えてもらえますか?

*WindowsでTiny Cを使用しています

サンプル コード: //Binarycheck には、以下に示す変数が含まれます。

void *binarycheck(int encoding, hero *curr[], int totalwarrior)
{
int toughtotal = 0;
int nimbletotal = 0;
int smarttotal = 0;
int skeptictotal = 0;
int mystictotal = 0;
int cursedtotal = 0;
int brutetotal = 0;
int shreddertotal = 0;
int vanillatotal = 0;
int typetotal = 0;
int class_num = 0;
int class_total[6];
int total = 0;
hero *type[3][6] = {{0},{0}};
hero *smart[3][6] = {{0},{0}};
hero *nimble[3][6]= {{0},{0}};
hero *tough[3][6]= {{0},{0}};   
hero *skeptic[]= {0};
hero *mystic[]= {0};
hero *cursed[]= {0};
hero *brute[]= {0};
hero *shredder[]= {0};
hero *vanilla[]= {0};

//This is a sample of assigning "curr[totalwarrior]' into its respective type array.
if ((encoding&128)==1 && (encoding&64)==1)
{
    smart[smarttotal][class_num] = curr[totalwarrior]; //class_num is 0 as of this moment. 
    total = smarttotal;
    type[total][class_num] = smart[smarttotal][class_num];
    smarttotal++;
    printf("\n::|Smart Type::|\n");
}
/*There will be 2 more of this code (above) since there will be 3 types array*/

//This is assigning "type[total][class_num]" into its respective class array.

if ((encoding&32)==1)
{
    class_num = 1;
    type[total][class_num] = vanilla[vanillatotal];
    class_total[1] = vanillatotal;
    vanillatotal++; //Vanilla
    printf("\n::|Vanilla Class::|\n");
}
/*There will be 5 more of this code (above) since there will be 6 class array*/

、、、seach_showを使用する必要がtotalありclass_numますtype[total][class_num]class_total

4

2 に答える 2

1

の開始時に定義されたすべての変数はbinarycheck、両方の関数に渡す必要があるものだと思います。

では、次のような構造を作成してみませんか。

struct Parameters {
  int toughtotal;
  int nimbletotal;
  int smarttotal;
  int skeptictotal;
  int mystictotal;
  int cursedtotal;
  int brutetotal;
  int shreddertotal;
  int vanillatotal;
  int typetotal;
  int class_num;
  int class_total[6];
  int total;
  hero *type[3][6];
  hero *smart[3][6];
  hero *nimble[3][6];
  hero *tough[3][6];
  hero *skeptic[];
  hero *mystic[];
  hero *cursed[];
  hero *brute[];
  hero *shredder[];
  hero *vanilla[];
};

init_parameters(struct Parameters* p)の開始時に行ったように、構造体の各メンバーを初期化するような関数が必要になりますbinarycheck

最後に、次のような関数を呼び出しました。

void binarycheck(struct Parameters *p, int encoding, product *curr[], int totalcurr)
void search_show(struct Parameters *p)
于 2013-09-30T14:45:00.490 に答える
1

これは的外れかもしれません。私はあなたが何を求めているのかまだ確信が持てません。しかし、私の提案には、コメントが提供するよりも優れた書式設定が必要です。

関数間で渡したい別の構造を探しているだけのように思えます。それを作成し、binarycheckfill に渡してから、に渡してsearch_show利用します。構造には、「によって使用されるすべての変数」と呼ばれるものが含まれますbinaryCheck。コードは次のようになります。

typedef struct binary_check_values {
    int toughtotal;
    int nimbletotal;
    int smarttotal;
    int skeptictotal;
    int mystictotal;
    int cursedtotal;
    int brutetotal;
    int shreddertotal;
    int vanillatotal;
    int typetotal;
    int class_num;
    int class_total[6];
    int total;
    hero *type[3][6];
    hero *smart[3][6];
    hero *nimble[3][6];
    hero *tough[3][6];
    hero *skeptic[];
    hero *mystic[];
    hero *cursed[];
    hero *brute[];
    hero *shredder[];
    hero *vanilla[];
} binaryCheckValues;

binaryCheckResults(int encoding, hero *curr[], int totalWarrior, binaryCheckValues *values) {
    values->toughtotal = 0;
    values->nimbletotal = 0;
    /* etc */
}
/* ... other code ... */
search_show(values);
于 2013-09-30T14:40:26.257 に答える