How to use values from functions in C -


I am trying to work on the project where I have been denied using the global variable. In my project, I have the following functions:

  int addAccount () {int ID_number = 0; Int id; Int id_array [10]; Double account_blanes; Double balance error [10]; Int choice = getChoice (); If (like == 1) {if (ID_number + 1> 10) {printf ("error \ n"); } And {ID_number = ID_number + 1; Printf ("Enter ID \ n"); Scanf ("% d", and ID); ID_array [ID_number - 1] = ID; Printf ("Enter the initial balance \ n"); Scanf ("% lf", & amp; account_balance); Balance_reary [id_number-1] = account_blanes; }} Return;  

I somehow need to get value for these variables and use them in any other function (especially ID, ID_number, and account_balance). The function I need for these values ​​is as follows:

  zero display () {int count; Int choice = getChoice (); Int ID_number = ID_number (); If (like == 2) {for (count = 0; count & lt; id_number; count ++) {printf ("account #% d: id% d \ n", count + 1, id_array [count]); Printf ("Account Balance% .2lf \ n", Balance Error [Calculation]); }}}  

I know how to return a value, but I do not know how many values ​​can be used outside the function where they are. Am I trying to make it possible or is it possible that I am going wrong about my project?

Use a struct :

 < Code> structure account {int calculation; Int ID_number; Int balance_array [10]; // etc etc }; Pass a pointer in   

addAccount :

  Add Zero Account (Account Account * Account) {account-> ID_number = 0 ; // etc}  

and then displayAccounts

  ZERO DISPLAY ACCOUNT (struct account * account) {}  

Example:

  Composition Account Account; AddAccount (& amp; Account); DisplayAccount (& amp; Account);  

Note that in C you do not need to use the prefix , unless you have to use the struct prefix, unless you have to type typedef


Comments

Popular posts from this blog

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

c# - WPF Expander overlay used in ItemsControl -

android - how to get distance of 2 beacons and make a condtion base on that distance -