[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Accepting three Different Inputs for three different Variables

Posted on 2004-08-09
4
Medium Priority
?
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 280 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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 and use conditional statements in the C programming language.
Suggested Courses

656 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