473,322 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Using enum Statement

8
Please help - I would like to pass to the routine MUX(Input, Phase) where Input is 0,1 and Phase 0,1,2 depending if the user presses the key (V,I) and (R,W,B) on the serial terminal.

I can not get my enum statement to do this, and don't want to resort to a switch statement as this does not seem a very elegant work around. I'm sure there is a better way?


#include <ctype.h>
#include <uart.h>

char ch;
enum {I, V} char Input;
enum {R, W, B} char Phase;

ch = getch();
printf("*** MUX setup mode: ***\nEnter input as 'V' or 'I'\n");
Input = toupper(getch());
if ((Input = 'I') || (Input = 'V')) // First get input
{
printf("Enter input as 'R', 'W' or 'B'\n");
Phase = toupper(getch()); // next get phase
if ((Phase = 'R') || (Phase = 'W') || (Phase = 'B'))
MUX(Input, Phase);
}

Thanks.
Aug 30 '07 #1
2 2124
RRick
463 Expert 256MB
enum {I, V} char Input;
enum {R, W, B} char Phase;
This might be a good idea, but enums don't work that way. You've got the right idea about enum values (but you got the I & V backwards and I doubt this will compile).

There is no automatic way to get the compiler to know that enum V corresponds to char 'V'. You have to use a swith statement to do that.
Aug 31 '07 #2
Toe001
8
Thank you for the answer. At least I know that it requires using a Switch statement.
Aug 31 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Marshall Mills | last post by:
As I understand it, loaded statement, a using declaration should be all I need to see an enum from within a namespace. The below code works fine with class, struct, and union. What gives? As the...
9
by: AngleWyrm | last post by:
"The C++ Programming Language" by Bjarne Stroustrup, copyright 1997 by AT&T, section 4.8 (pp 77): "A value of integral type may be explicitly converted to an enumeration type. The result of such a...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
4
by: Nikhil Patel | last post by:
Hi all, I am a VB6 programmer and learning C#. I am currently reading a chapter on types. I have question regarding enums. Why do we need to convert enum members to the value that they represent?...
13
by: Adam Blair | last post by:
Is it possible to bind a switch statement to an Enum such that a compile-time error is raised if not all values within the Enum are handled in the switch statement? I realise you can use default:...
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
10
by: Rick Palmer | last post by:
I have an app I'm working on that will allow a user to run one of 5 reports. The report names are in a combobox on my form. I have a sub defined for each report that has the exact same name as is...
9
by: subramanian | last post by:
Hello. Consider the following code fragment : enum TestEnum { val1 = 10, val2 = 100, val3 = 1000 }; class Test { public : enum TestEnum { val1 = 1, val2 val3 }; Test(int i = 0, int j = 0,...
5
by: alan4cast | last post by:
I posted this in the VB forum several days ago, and got no reply. Since it's specific to VB.Net I thought I'd try it here. I'm a relatively-experienced VB programmer, but I'm still working on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.