enum structure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <time.h>
using namespace std;

enum calendar{ jan = 1 , feb , mar , apr , may , jun , july , aug , sep , oct , nov , dec };

int main(){

	char date[9];
	_strdate(date);

	for( int i = 2 ; i < 9 ; i++ ){
		if( i >= 4 ){
			date[i] = date[i+2];
		}
		else{
			date[i] = date[i+1];
		}
	}
	cout << date << endl;

	char month[2];
	for( int i = 0 ; i < 2 ; i++ ){
		month[i] = date[i];
	}

	cout << month << endl;
	

	system( "pause" );
	return 0;
}


just want to compare my first 2 char array then compare with enum to display the month, any suggest?
0) char month[2];
If you want to store c-string representation of month, it should be char month[3];: 2 symbols for month number and another one for terminating zero.

1) there is no int -> enum conversions. It is strictly one way (enum -> int) only.
And why do you need enum at all? Why not just use month numbers? You do understand that enums is basically an integers and will not retain their names after compilation, do you?
because actualy no wi stor emy date as

 
04/12/13
when using _strdate(date)

now i store into new char that without that slash
 
041213


so now i wan to let that 04 is mean april

i wan my program display as
 
april 12 13
. something like that . possible to do?

then how should my coding look like?
1
2
3
4
const std::string month[12] = {"January", "February", /*...*/ "December"};
//take month number in m character array
int mon(std::atoi(m) - 1);
std::cout << month[mon];
Nw my date have 9 array. Store as the date. Bt i just wan to take the [0][1] of date to take the month. Bt whn i create it should b declare char month with three array . Thn push the date first n second array into month variable. Did i correct? Thn oni to something like yours?
1
2
3
char date[9];
//get date
char m[3] = {date[0], date[1], '\0'};
Topic archived. No new replies allowed.