How to increment an enum in C?

2

Objectively how do I increment ++ or += 1 one of the variables of enum (the increment will be in a loop / switch ):

enum {um = 0, dois = 0 ... seis = 0};

I read this question and I did not quite understand. Is there a better structure hint for storing the data (which are six strings)?

    
asked by anonymous 22.03.2017 / 05:05

1 answer

3

There's no secret and that's what that code shows. The enumeration is created. It declares a variable of the enumeration type, assigns one of the possible values to the variables, and can already use an enumeration constant, although it can be any value, there is no use check, and then increment. The variable will be a normal integer.

#include <stdio.h>

typedef enum {um = 1, dois = 2, tres = 3} Numeros;

int main(void) {
    Numeros numero = um;
    numero++;
    printf("%d", numero);
}

See running on ideone . And on the Coding Ground (now inaccessible site). Also put it on GitHub for future reference .

This is the question you asked and it is answered. But the description also indicates that you do not want this. The first thing you need to define is whether you need string , or you just need a set of variables that hold some values and that these values should be incremented, array of int very simple, which is a much more basic resource of C. and as already programmed in C before should know how.

There is a question that shows the practical use of this .

    
22.03.2017 / 10:52