Separating Long strings with newline

You must understand the Game Editor concepts, before post here.

Separating Long strings with newline

Postby EvanAgain » Thu Jan 31, 2013 9:37 pm

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.
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Separating Long strings with newline

Postby skydereign » Thu Jan 31, 2013 10:04 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest