Page 1 of 1

Separating Long strings with newline

PostPosted: Thu Jan 31, 2013 9:37 pm
by EvanAgain
Code: Select all
//FOR LOOP FOR SPLITTING LONG ITEM NAMES INTO TWO LINES
      for(i = 0; i < (sizeof(myActor->ItemName)/sizeof(char)-1); i++)
      {

       
          //NEVER RUNS??
          if(i >= ( ( sizeof(myActor->ItemName)/sizeof(char)-1 )/2 )
             && myActor->ItemName[i] == ' ')
          {
              description[i] = newline[0];
              i++;
           }


          description[i] = myActor->ItemName[i];
      }




I was able to get this to work if I look for two specific character in the string using this loop:


if(myActor->ItemName[i+1] == 'o' && myActor->ItemName[i+2] == 'f')

But the problem is I need it to separate once it reaches a certain point. I can think of many work arounds but I want this to work a specific way so that I don't have to have strict string lengths.

I, also, know that this specific code should turn all spaces after half the length into newline character. I just want it to run once and I will get it to do that after I can figure out why it never even runs this loop once.

Re: Separating Long strings with newline

PostPosted: Thu Jan 31, 2013 10:04 pm
by skydereign
You are using char arrays, right? The size of a char array is the total capacity you declared it with. So perhaps your test case string is less than half the size of the actual string? You should be using strlen if you want the number of characters the string has.