Noob - Cycle through stored names and skip blanks

Posted by ActiveJimBob on Stack Overflow See other posts from Stack Overflow or by ActiveJimBob
Published on 2013-07-01T15:46:36Z Indexed on 2013/07/01 16:21 UTC
Read the original article Hit count: 253

Filed under:
|
|
|

NOOB trying to make my code more efficient. On scroll button push, the function 'SetName' stores a number to integer 'iName' which is index against 5 names stored in memory. If a name is not set in memeory, it skips to the next.

The code works, but takes up a lot of room. Any advice appreciated. Code:

    #include <string.h>
    int iName = 0;
    int iNewName = 0;

    BYTE GetName ()
    {
     return  iName;
    }


    void SetName (int iNewName)
    {

      while (iName != iNewName)
      {

      switch (byNewName)
       {
        case 1:
        if (strlen (memory.m_nameA) == 0)
         new_name++;
        else
         iName = iNewName;
        break;

        case 2:
        if (strlen (memory.m_nameB) == 0)
         new_name++;
        else
         iName = iNewName;
        break;

        case 3:
        if (strlen (memory.m_nameC) == 0)
         new_name++;
        else
         iName = iNewName;
        break;

        case 4:
        if (strlen (memory.m_nameD) == 0)
         new_name++;
        else
         iName = iNewName;
        break;

        case 5:
        if (strlen (memory.m_nameE) == 0)
         new_name++;
        else
         iName = iNewName;
        break;

        default:
        iNewName = 1;
        break;
       } // end of case

      } // end of loop

    } // end of SetName function


void main ()
 {
  while(1)
  {
  if (Button_pushed)
   SetName(GetName+1);
  } // end of infinite loop
} // end of main

© Stack Overflow or respective owner

Related posts about c

    Related posts about string