473,387 Members | 1,592 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,387 software developers and data experts.

enum type usage

In my homework i need to use enum type input,and these inputs will contain a port number and a description.

Here is the input:
HTTP : 80 “Hypertext Transfer Protocol”
SSH : 22 “Secure Shell”
SMTP : 25 “Simple Mail Transfer Protocol”
DNS : 53 “Domain Name System”
TELNET : 23 “Telecommunication Network”
IMAP : 143 “Internet Message Access Protocol”

i've written 2 structs below:
typedef enum{
HTTP = 80;
SSH = 22;
SMTP = 25;
DNS = 53;
TELNET = 23;
IMAP = 143;
}port_numbers;

typedef struct{
enum port_numbers number;
string definition;
}Ports;

i have difficulties with assinging definitions to port numbers.how can i match each port number and definiton?i'm going to print them to a file when e.g: HTTP word is passed as an enum type parameter to a function i define

Thanks in advance
Oct 18 '06 #1
3 5209
Banfa
9,065 Expert Mod 8TB
i've written 2 structs below:
typedef enum{
HTTP = 80;
SSH = 22;
SMTP = 25;
DNS = 53;
TELNET = 23;
IMAP = 143;
}port_numbers;
This is not a structure it is an enum and the 2 things are completely different. Also you have the syntax wrong it should be

Expand|Select|Wrap|Line Numbers
  1. typedef enum{
  2.     HTTP = 80,
  3.     SSH = 22,
  4.     SMTP = 25,
  5.     DNS = 53,
  6.     TELNET = 23,
  7.     IMAP = 143
  8. }port_numbers;
  9.  
Oct 18 '06 #2
tyreld
144 100+
Can you show us more code? Have you actually written the function that assigns the port numbers? You haven't given enough info for us to know what the exact problem you are having is.

One thing I have noticed is that you are using the enum identifier in your struct definition when you typedefed the enum definition to a standalone name. There is no type "enum port_numbers", but there is a type "port_numbers" that is a enum. Take a luck at my modified code. There is a type "port_numbers" of type "enum e_port_numbers" and a type "Ports" of type "struct s_Ports". The typedef keyword can have subtle implications since both struct and enum have optional names.

Expand|Select|Wrap|Line Numbers
  1. typedef enum e_port_numbers {
  2.    HTTP = 80,
  3.    SSH = 22,           // use commas not semi-colons here
  4.    SMTP = 25,
  5.    DNS = 53,
  6.    TELNET = 23,
  7.    IMAP = 143
  8. } port_numbers;
  9.  
  10. typedef struct s_Ports {
  11.    port_numbers number;   // noticed I've changed this line
  12.  
  13.    enum e_port_numbers number2;  // and added an example of using the
  14.                               // non-typedefed type name
  15.    string definition;
  16. } Ports;
  17.  
  18.  
Oct 18 '06 #3
when HTTP is passed as an enum type argument to a function i want to print its port number and description.
function(...,HTTP,...){
cout << HTTP << port number of HTTP << description of HTTP << endl;
}

i hope i could explain what i need
Oct 19 '06 #4

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

Similar topics

2
by: Alexander Lurye | last post by:
Hi! I have the following problem: Suppose that we have the following class: class A; class AException {
21
by: Bilgehan.Balban | last post by:
Hi, I have two different enum definitions with members of same name. The compiler complains about duplicate definitions. Is this expected behaviour? Can't I have same-named fields in...
10
by: James Brown | last post by:
I have the following enum declared: enum TOKEN { TOK_ID = 1000, TOK_NUMBER, TOK_STRING }; (it goes on and on like that) This is what I would like to do: TOKEN t1 = TOK_ID; // ok...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
16
by: Simon | last post by:
Hi all, I think I've seen someone passing an emumeration in code before. Can anyone tell me if thats possible and why i would want to. Many thanks Kindest Regards
2
by: tony collier | last post by:
I have the following in one of my .aspx pages: ..... <script runat="server"> enum bookstores { Amazon,
6
by: Michael Isaacs | last post by:
Regarding use of enum's, I am wondering what the cost of memory is when creating the enumeration on the calling side, and then using it on the function/method side. See example below. If I...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
0
by: tony_in_da_uk | last post by:
*** I posted this on comp.lang.c++.moderated a couple days ago, and got a near-flippant response from someone who clearly didn't take the time to consider the import. I replied, and it's still not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.