I am working on some code to parse log data, this part in particular is used to translate the decimal form of a month to a human form ( so 1 would be jan ), and to accomplish this I am trying to use a combination of a for loop and an if statement, and had thought that I could simply use a variable as the number for the statement to retrieve the array cell, but it did not work out as expected, so if someone could offer advice as to how I can do this I would really appreciate it, thanks!
(here is the main chunk of the code)
for ( x = 0; x < 11; x++ ) {
int altint = 1 + x;
if ( dmon == altint ) {
printf( "%s\n", field_month[x] );
{break;}
}
}
I’d like to suggest that you not use a
forloop and instead look up the element that you want directly:If your
dmonis 1-indexed (1for January, ..,12for December), then a slight change: