Solved

Accepting three Different Inputs for three different Variables

Posted on 2004-08-09
4
181 Views
Last Modified: 2010-04-15
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!
0
Comment
Question by:caleno
  • 2
4 Comments
 
LVL 5

Expert Comment

by:lemmeC
ID: 11753101
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
 
LVL 1

Expert Comment

by:ageraldnaveen
ID: 11753312
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
 

Author Comment

by:caleno
ID: 11756974
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
 
LVL 1

Accepted Solution

by:
ageraldnaveen earned 70 total points
ID: 11759835
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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question