13 Jul, 2016, gamer_liko wrote in the 1st comment:
Votes: 0
Hello,
I am learning C(using tbamud). I have a question. I am wanting to format some code and make it align.
Example:
Fire1 Fire2 Fire3 Fire4 Fire5
Lets say I want that above code to format after every for words
How I want it to output:

Fire1 Fire2 Fire3 Fire4(insert a \r\n)
Fire5

So I was thinking would it be something like this

send_to_char(ch, "%s%s", skill_name, (buf % 4) ? "\r\n" : "");


thanks for the help!
13 Jul, 2016, Davion wrote in the 2nd comment:
Votes: 0
You just have to keep track of how many skills your sending. Typically just before the for() loop you declare a new variable, lets call it displayed.

edit: You also need to add the spacing for each name. You do that by adding an integer between the first % and 's' in the stc.
int displayed = 0;

for(…)

send_to_char(ch, "%-15s%s", skill_name, (++displayed % 4) ? "\r\n" : "");
13 Jul, 2016, gamer_liko wrote in the 3rd comment:
Votes: 0
Hmm.
This is what I have put and it is wrong:

for(a=0;a<10;a++) {
sprintf(buf, "1 2 3 4 5 6 7 8");
send_to_char(ch, "%-10s%s", buf, (a%2)?"\r\n":" ");
}


What I am trying to do is line up score. Say if each line goes over 10 characters or words it will format:

send_to_char(ch, "Character Level: %d", GET_LEVEL(ch));

Now what I want to do is have it count all the character letters or words in the code above. I know strlen counts the length of the line above.
What I am trying to do is say strlen counts 30 characters itll format.

Sorry for asking so much!
13 Jul, 2016, gamer_liko wrote in the 4th comment:
Votes: 0
So I rewrote list_skills and it does \r\n after four skills:

void list_skills(struct char_data *ch)
{
const char *overflow = "\r\n**OVERFLOW**\r\n";
int i, sortpos, ret, a;
size_t len = 0;
char buf2[MAX_STRING_LENGTH];

len = snprintf(buf2, sizeof(buf2), "You know the following %ss:\r\n", SPLSKL(ch));

for(a=0, sortpos=0;sortpos <= MAX_SKILLS; sortpos++) {
i = spell_sort_info[sortpos];
if(GET_LEVEL(ch)>= spell_info[i].min_level[(int)GET_CLASS(ch)]) {
ret = snprintf(buf2 + len, sizeof(buf2) - len, "%-20s%s", spell_info[i].name, (a++%4 == 3)?"\r\n":" ");
if(ret< 0 || len + ret >= sizeof(buf2))
break;
len += ret;
}
}
if (len >= sizeof(buf2))
strcpy(buf2 + sizeof(buf2) - strlen(overflow) - 1, overflow);

page_string(ch->desc, buf2, TRUE);
}


Hopefully, I can use the same method to align up the score.
0.0/4