Solved

Accepting three Different Inputs for three different Variables

Posted on 2004-08-09
4
177 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now