Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass function as the parameter of another function in C?
    primarykey
    data
    text
    <p>I realize that there are already too many questions about my question but the answers I have seen so far assumes the return values of the function that is to be a pointer, <code>int</code> value.</p> <p>I have two functions, namely <code>void binarycheck(int encoding, product *curr[], int totalcurr)</code> and <code>void search_show()</code>.</p> <p><code>binarycheck</code> basically gets the <code>encoding</code> value from the array struct named <code>curr</code> (curr contains mixed variables of strings and int). Its purpose is to classify the array <code>curr</code> into 3 major types and 5 subclasses after checking the <code>encoding</code> of each array curr via bitwise function.</p> <p>The subclasses are included within the typedef struct that was used to form <code>curr</code>. Like:</p> <pre><code>typedef struct nodebase{ char name[254]; char company_name[254]; int encoding; double price; struct nodebase *next; struct nodebase *Class; }product; </code></pre> <p>Now, after using the <code>binarycheck</code> function, <code>void search_show</code> will basically ask user for his preferred 1) Type then 2) Subclass then <code>void search_show</code> will print the products that has been classified as the user's chosen Type and Subclass.</p> <p>So, <code>void search_show</code> will have to use the results of <code>void binarycheck</code> that are in forms of int (for counting the presence of each classified arrays) and arrays (for classifying data).</p> <p>I was thinking of a "brute force" way by putting all variables used by <code>void binarycheck</code> as the parameter of <code>void search_show</code> but the variables are too much to add.</p> <p>Can anyone help me how to "re-use" all the variables and the results of the first function in the second function?</p> <p>*I am using Tiny C on Windows</p> <p>Sample Code: //Binarycheck will contain variables shown below:</p> <pre><code>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&amp;128)==1 &amp;&amp; (encoding&amp;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&amp;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*/ </code></pre> <p>The <code>seach_show</code> has to use <code>total</code>, <code>class_num</code>, <code>type[total][class_num]</code>,<code>class_total</code> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload