Sponsored Content
Full Discussion: enumeration types in C
Top Forums Programming enumeration types in C Post 302224138 by cleopard on Tuesday 12th of August 2008 09:25:07 AM
Old 08-12-2008
enumeration types in C

If I want to declare an array of structures in C and have the number of items in that array to correspond to the items of an enumeration, is there a way to access the maximum value in the enumeration when declaring the array?

For instance:

typedef struct
{
various fields....
} fruit_rec;

enum fruit_info {apple, orange, banana}

fruit_rec fruits[3];


Instead of hard-coding a '3' in the 'fruits' declaration, is there a way I can access the number of items in the enumeration? In the old DoD language, Ada, one could do something like, " fruit_rec fruits[fruit_info] " .

I don't think there is a way to do what I'm asking, but I thought I'd ask as it would be a cleaner way of declaring things. Even if I can't do something like that, I know I can still refer to the elements as "fruits[apple}" , "fruits[orange]", etc. Thank you.
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

servers types

dear sir , i would like to ask about sun solaries servers generations ? i hear about sparc and ultra . i want to know the versions , and is there other servers types ?? Thank (3 Replies)
Discussion started by: tamemi
3 Replies

2. UNIX for Dummies Questions & Answers

So many types of LINUX's!

I installed Redhat into my system. The reason? This was the version my friend was running and he told me about this one, so I downloaded and installed it. Simple enough :D But as I am searching the net, I am coming across many other forms of linux made by other companies. Redhat seems to be... (2 Replies)
Discussion started by: Minnesota Red
2 Replies

3. Programming

X-Windows Enumeration

Hi, I'm new to x-windows system and I have a few questions: 1. How can I write a C program to enumerate all the windows on the local and remote computers? In other words: How can I create a list of all the windows in the system (maximized/minimized/active/not active ....)? 2. How can I... (0 Replies)
Discussion started by: itaihoe
0 Replies

4. UNIX for Dummies Questions & Answers

Two types of pipes?

What is the difference between: cd /tmp tar -cf - *.txt |gzip > tmp_txt.tar.gz and cd /tmp mknod pipe p gzip < pipe > /tmp/tmp_txt1.tar.gz & tar -cf pipe *.txt Apart from the fact that we have to create the pipe file manually, is there any difference in the performance of the two?... (5 Replies)
Discussion started by: blowtorch
5 Replies

5. UNIX for Dummies Questions & Answers

mime types

Hi, I am trying to launch an ogg movie from a pdf file which has been produced with pdflatex and \movie {\centerline{\includegraphics {grafiques_xerrades/un_manolo_amb_camera.pdf}}} {hlims_xerrades/XocCumuls.ogg} The switch "externalviewer" makes kpdf launch the default... (5 Replies)
Discussion started by: pau
5 Replies

6. UNIX for Dummies Questions & Answers

Un-compression types...

Hi Folks, As I am familiar wih both types compresion forms: gun-zip and .rpm. My questions is how do I uncompress gunz.zip type? As the .rpm I can double click and it will extract...Can someone shed some light on this and thank you... M (2 Replies)
Discussion started by: Mombo_Z
2 Replies

7. What is on Your Mind?

What Types of Food Do You Like The Most?

On another simple topic, multiple choice answers OK ( you can pick more than one or suggest others - we will add your suggestions to the poll ). What Types of Food Do You Like The Most? (27 Replies)
Discussion started by: Neo
27 Replies

8. Shell Programming and Scripting

Cp -r except certain file types

the following excludes certain directories successfully cp -r probe/!(dir) /destination I want to exclude certain file types and tried unsuccessfully cp -r probe/!(*.avi) /destination (2 Replies)
Discussion started by: tmf
2 Replies
MUNGE_ENUM(3)						    MUNGE Uid 'N' Gid Emporium						     MUNGE_ENUM(3)

NAME
munge_enum_is_valid, munge_enum_int_to_str, munge_enum_str_to_int - MUNGE enumeration functions SYNOPSIS
#include <munge.h> int munge_enum_is_valid (munge_enum_t type, int val); const char * munge_enum_int_to_str (munge_enum_t type, int val); int munge_enum_str_to_int (munge_enum_t type, const char *str); cc ... -lmunge DESCRIPTION
The munge_enum_is_valid() function checks if the given value val is a valid MUNGE enumeration of the specified type type in the software configuration as currently compiled. Some enumerations correspond to options that can only be enabled at compile-time. The munge_enum_int_to_str() function converts the MUNGE enumeration val of the specified type type into a text string. The munge_enum_str_to_int() function converts the NUL-terminated case-insensitive string str into the corresponding MUNGE enumeration of the specified type type. RETURN VALUE
The munge_enum_is_valid() function returns non-zero if the given value val is a valid enumeration. The munge_enum_int_to_str() function returns a NUL-terminated constant text string, or NULL on error; this string should not be freed or modified by the caller. The munge_enum_str_to_int() function returns a MUNGE enumeration on success (i.e., >= 0), or -1 on error. ENUM TYPES
The following enumeration types can be specified. MUNGE_ENUM_CIPHER Specify enumerations for the available cipher types. MUNGE_ENUM_MAC Specify enumerations for the available MAC types. MUNGE_ENUM_ZIP Specify enumerations for the available compression types. ERRORS
Refer to munge(3) for a complete list of errors. EXAMPLE
The following example program illustrates how a list of available cipher types can be queried. #include <stdio.h> /* for printf() */ #include <stdlib.h> /* for exit() */ #include <munge.h> int main (int argc, char *argv[]) { int i; const char *p; munge_enum_t t = MUNGE_ENUM_CIPHER; for (i = 0; (p = munge_enum_int_to_str (t, i)) != NULL; i++) { if (munge_enum_is_valid (t, i)) { printf ("%2d = %s ", i, p); } } exit (0); } AUTHOR
Chris Dunlap <cdunlap@llnl.gov> COPYRIGHT
Copyright (C) 2007-2011 Lawrence Livermore National Security, LLC. Copyright (C) 2002-2007 The Regents of the University of California. MUNGE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Additionally for the MUNGE library (libmunge), you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SEE ALSO
munge(1), remunge(1), unmunge(1), munge(3), munge_ctx(3), munge(7), munged(8). http://munge.googlecode.com/ munge-0.5.10 2011-02-25 MUNGE_ENUM(3)
All times are GMT -4. The time now is 10:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy