Note that there are some explanatory texts on larger screens.

plurals
  1. POIterate through 2 dimensional array in C
    primarykey
    data
    text
    <p>I have a 2 dimensional array that contains string values. I am using an enum to keep track of the first index of the array when iterating. I am trying to find the enum (first dimension of an array) that a given string matches. Right now, my the way I'm iterating over the arrays and checking for values doesn't seem to seem to work 100% of the time because it will return the wrong enum. Does anyone see what I'm doing wrong, or know of a better way to get the index of the first array based on a matched string in the second?</p> <p>NOTE: I am using Arduino, and am using String objects instead of char*.</p> <pre><code> enum conditionType { CLEAR = 0, OVERCAST, CLOUDY, RAIN, THUNDERSTORM, SNOW }; int conditionsIndex[6] = { CLEAR, OVERCAST, CLOUDY, RAIN, THUNDERSTORM, SNOW}; const char *conditions[][20] = { // CLEAR { "Clear" } , // OVERCAST { "Partly Cloudy" } , // CLOUDY { "Shallow Fog", "Partial Fog", "Mostly Cloudy", "Fog","Overcast", "Scattered Clouds" } , // RAIN { "Drizzle", "Rain", "Hail", "Mist", "Freezing Drizzle", "Patches of Fog", "Rain Mist", "Rain Showers", "Unknown Precipitation", "Unknown", "Low Drifting Widespread Dust", "Low Drifting Sand" } , // THUNDERSTORM { "Thunderstorm", "Thunderstorms and Rain", "Thunderstorms and Snow", "Thunderstorms and Ice Pellets", "Thunderstorms with Hail", "Thunderstorms with Small Hail", "Blowing Widespread Dust", "Blowing Sand", "Small Hail", "Squalls", "Funnel Cloud" } , // SNOW { "Volcanic Ash", "Widespread Dust", "Sand", "Haze", "Spray", "Dust Whirls", "Sandstorm", "Freezing Rain", "Freezing Fog", "Blowing Snow", "Snow Showers", "Snow Blowing Snow Mist", "Ice Pellet Showers", "Hail Showers", "Small Hail Showers", "Snow", "Snow Grains", "Low Drifting Snow", "Ice Crystals", "Ice Pellets" } }; int currentCondition; for ( int i = 0; i &lt; ( sizeof(conditionsIndex) / sizeof(int) ); i++ ) { int idx = conditionsIndex[i]; for (int j = 0; j &lt; ( sizeof(conditions[idx]) / sizeof(String) ); j++ ) { if ( forecast.equals(conditions[idx][j]) ) { currentCondition = idx; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload