我意识到关于我的问题已经有太多问题了,但到目前为止我看到的答案都假设函数的返回值是一个指针,int
值。
我有两个功能,即void binarycheck(int encoding, product *curr[], int totalcurr)
和void search_show()
。
binarycheck
基本上encoding
从名为的数组结构中获取值curr
(curr 包含字符串和 int 的混合变量)。其目的是通过按位函数检查每个数组currcurr
的值后,将数组分为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
将打印已分类为用户选择的类型和子类的产品。
因此,void search_show
将不得不使用void binarycheck
int 形式的结果(用于计算每个分类数组的存在)和数组(用于分类数据)。
我正在考虑一种“蛮力”方式,将所有使用的变量void binarycheck
作为参数,void search_show
但变量太多无法添加。
谁能帮助我如何在第二个函数中“重用”所有变量和第一个函数的结果?
*我在 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