Help with strlen

So I created a box of asterisk so that I can output my data into so it'll look something like this

************
*          *
*          *
*          *
*          *
*          *
************     

But when I output datas into it, it becomes distorted.

************
*  Hello       *
*  World!       *
*  It's        *
*  Me!        *
*          *
************ 

I know what I'm suppose to do, but I just don't know how to implement it. I'm suppose to use the strlen to get the length of the string and then subtract that string from the spaces in between the box.
1
2
3
//printf("%c  %s       %c",'*',var1,'*');
int format1 = 12 - strlen(var1);
printf("%c   %s&format1c",'*',var1,'*');

But it won't read format1. So my question is how can I implement this so that all the asterisks on the right will automatically format to fit the box?
Does this help?

1
2
3
4
5
6
7
8
9
#include <stdio.h>

int main()
{
    printf("==> %s <==\n", "hi!");
    printf("==> %8s <==\n", "bye!");

    return 0;
}


==> hi! <==
==>     bye! <==


See width description in the Parameters section on this page: printf
http://www.cplusplus.com/reference/cstdio/printf/#parameters

Andy
Last edited on
Thank you for sending me the link. It did solve my problem.
Topic archived. No new replies allowed.