• C

Accepting three Different Inputs for three different Variables

Hi, I have an appliction where through a keypad a user enters three parameters for three different variables. For instance, timeOn, timeOff and Frequency. Each of these values will be less than 50. I need to use a function that will accept all these inputs and stores them in each corresponding variable. I am thinking of a structure, with 3 members, but I am not too sure how to do that.

Here is an idea of what I have so far.

unsigned char User_start[2] = {0xFF, 0xFF};      // reset value       
unsigned char User_stop[2] = {0xFF, 0xFF};      // reset value
unsigned char Freq_input[2] = {60};                 // reset value

void ent_ontime (unsigned char key)
{
if (input_val < 2)
      {
      if (process == 1);
      {
      User_start[input_val++] = key;       // need to do the same thing for other two
      numdsp(0xC2, key, 0, 1);               // parameters
      }
      return;
      }
      process++;                        
}

if process == 2, then user_stop will be required.
if process == 3, then Freq_input will be required.
Would an structure be a good approach for this application
I have taken care of the keypad configuration


Thanks!
calenoAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ageraldnaveenConnect With a Mentor Commented:
Sim is an array of pointers as per declaration...

unsigned char *Sim[3];

array of pointers can be access like a two D array.. thats how it works..

">>I think the first declaration is a structure with three members"
what declaration??? i dont see any structure there!!

i would like to modify little on my code.. change the declaration to:

unsigned char *Sim[3]={User_start, User_stop, Freq_input};

this is enough for this to work..

hope that helps.
0
 
lemmeCCommented:
unsigned char User_start[2] = {0xFF, 0xFF};      // reset value      
unsigned char User_stop[2] = {0xFF, 0xFF};      // reset value
unsigned char Freq_input[2] = {60};                 // reset value

void ent_ontime (unsigned char key)
{
    int input_val = 0;
 
    if (process == 1)
    {
        while(input_val < 2)
        {
            User_start[input_val++] = key;      
            numdsp(0xC2, key, 0, 1);            
        }
    }
    else if (process == 2)
    {
        while(input_val < 2)
        {
            User_stop[input_val++] = key;      
            numdsp(0xC2, key, 0, 1);            
        }
    }
    else if(process == 3)
    {
        while(input_val < 2)
        {
            Freq_input[input_val++] = key;      
            numdsp(0xC2, key, 0, 1);            
        }
    }

    process++;  
    return;                
}
0
 
ageraldnaveenCommented:
unsigned char User_start[2] = {0xFF, 0xFF};      // reset value      
unsigned char User_stop[2] = {0xFF, 0xFF};      // reset value
unsigned char Freq_input[2] = {60};                 // reset value

unsigned char *Sim[3]={(unsigned char*)&User_start,
            (unsigned char*)&User_stop,
            (unsigned char*)&Freq_input};

void ent_ontime (unsigned char key)
{
    Sim[process][input_val++] = key;
}

then u shall as usually access them from the respective variables..

hope that helps!
0
 
calenoAuthor Commented:
ageraldnaveen, I like your suggestion
I think the first declaration is a structure with three members. I think I know how could I access them.

But can you explain this: Did you create a 2 dim. array?
How does this work?  

Sim[process][input_val++] = key;

I will be looking in my C book as well
Thanks!


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.