Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to work with arrays of strings in the C framework
#1
I am running into an unexpected issue when trying to store an array of text to call up in a printing function.

The printing function is:

Code:
void PrintStringLines(u8 Plane, u8 Palette, u8 XPos, u8 YPos, const char * theString)
{
   u16 * Screen;
   u8 originalXPos=XPos;

   switch (Plane)
   {
      case SCR_1_PLANE:
         Screen = SCROLL_PLANE_1;
         break;

      case SCR_2_PLANE:
         Screen = SCROLL_PLANE_2;
         break;

      default:
         return;
   }

   while (*theString)
   {
      u16 Offset = ((u16)YPos * 32) + XPos;
      u16 Value = *theString;
     
      if(Value==47){
          YPos++;
          XPos=originalXPos-1;
     
      }else{
          Value = *theString + ((u16)Palette << 9);
          Screen[Offset] = Value;
      }

      theString++;
      XPos++;
   }
}


Test 1 is to create a 2-dimensional array like this:
Code:
const char dialogueTest[][150] = {
  "Line 1 of text",
  "Line 2 of text",
  "Line 3 of text",
};

The function can be called as follows and works just fine:
PrintStringLines(SCR_2_PLANE, 0, 1, 9, dialogueTest[0]);

The only issue is that there is a lot of wasted space having to take up 150 bytes per line.

My issue is that I cannot seem to find a way to work with the data if it is defined as:
Code:
const char * dialogueTest[] = {
  "Line 1 of text",
  "Line 2 of text",
  "Line 3 of text",
};

Any tips for printing from this?  It doesn't seem to matter if I cast it.
Reply


Messages In This Thread
How to work with arrays of strings in the C framework - by winteriscoming - 01-31-2023, 04:23 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)