void functions
複数の変数(コード全体で同じ)があるため、関数の個々の出力に依存する複数の関数があり、各関数の出力はそれらに「保存」され、別の関数に渡されます。
そこで、必要なすべてのコードstatic ....
の直後にこれらの変数をグローバル変数にすることにしました。#include...
すべての関数 (合計 14 個の関数、 all void
) を 4 つ呼び出すだけで利用できました (各関数は、独自の関数を処理した後、結果を別の関数に渡し、一連の受け渡しの後、それらのうちの 4 つだけが必要です。呼ばれるint main()
)
ここで、他のすべての関数が以前に宣言されたグローバル変数に「コピーして入れた」データに依存してvoid function
いるため、グローバル変数をパラメーターとして必要とする別のものを作成しました。void function
(データをグローバル変数に格納することはできないと聞いたので、これは機能していません。)
個々の関数の出力を必要とする一連の関数を作成する他の方法があれば、誰か教えてもらえますか?
変数がきちんと格納されているか確認したのでprintf
、#3 の直後のメソッドを使ってみました。からの値が出力されることを期待していたときに、何も出力されないことがわかりましたstruct data
。
元:
typedef struct database{
//... variables
}data;
typedef struct itembase{
//... variables
}item;
static data user1;
static data user2;
static data *pointer[10000];
static item *pointer2[10000];
static item current[10000]; //Shares same value of the bracket with *pointer2
static data sectionA[1][10000];
static data sub_section[3][10000];
static int datacounter = 0; //..will be put inside the bracket of *pointer
static int itemcounter = 0; //..will be put inside the bracket of *pointer2
static int typenum = 0; ..will be put inside the first bracket of all the sections and subsections
static int section_count = 0; //..will be put inside the second bracket of all sections
static int sub_section_count[3] = {0}; //..will be put inside the second bracket of all sub_sections. The [3] will be the value of the typenum.
void load_data() // Accepts User's input and store them into struct data's variable using singly-linked list
{
//.... All data will be stored to *pointer[datacounter]
binarycheck(pointer[datacounter]->encoding,*pointer,datacounter);
//.... The `typedef struct` of data contains 12 variables. After storing 12 variables, datacounter will be ++ and the program will still continue to accept input from the user
}
void load_item()
{
//.... All item will be stored to *pointer2[itemcounter]
memcpy(¤t[itemcounter],pointer2[itemcounter],sizeof(item));
}
void binarycheck(data encoding,data *pointer,int datacounter)
{
if ((encoding&128)==128){
typenum = 3;
memcpy(§ionA[typenum][section_count],pointer,sizeof(data));
sub_sectionA[typenum][sub_section_count[typenum]] = sectionA[typenum[section_count];
section_count++;
sub_section_count++;
}
}
void askitem(data user)
{
// Tried putting `printf(" %s User1 Data#1",user1.firstdata);` and it works perfectly fine.
// Ask for user's selection on item
// If the item is found, then the content of that item will modify the data of the variable of `user`
}
void askinput(data user)
{
int whattype = 0;
int whatsub = 0;
printf("What type do you want?: \n);
scanf("%d",&whattype);
if (whattype == 1)
{typenum = 1;}
printf("What Sub type do you want?: \n);
scanf("%d",&whatsub);
if (whatsub == 1)
{ user = sub_sectionA[typenum][sub_section_count[typenum]];}
askitem(user);
}
void final_print(data user, data user2)
{
printf("%d\n",user.Adata);
printf("%d\n",user2.Adata);
}
int main()
{
load_data();
load_item();
askinput(user1);
//Tried putting `printf(" %s User1 Data#1",user1.firstdata);` but nothing shows.
askinput(user2);
//Nothing shows
final_print(user1,user2); //Nothing shows
}