-1

I'm working on a program that has you enter your name, and the program then puts it into a square. For example, for the input "Zyad" I would expect the output:

 ********
|        |
|  Zyad  |
|        |
 ********

Now I want to be able to enter two names (for example first and last name) and get the same sort of output.

The input of "Zyad Sabry" would yield

 **************
|              |
|  Zyad Sabry  |
|              |
 **************

My Code :

scanf("%s",name);
n = strlen(name);
printf(" ");

for(i=0;i<n+4;i++)
    printf("*");
    printf("\n");
    printf("|");

    for(i=0;i<n+4;i++)
        printf(" ");
        printf("|");

    printf("\n");
    printf("|");

    for(i=0;i<(n+4)-n-2;i++)
        printf(" ");
        printf("%s  |");

    printf("\n");
    printf("|");

    for(i=0;i<n+4;i++)
        printf(" ");
        printf("|");

    printf("\n");
    printf(" ");

    for(i=0;i<n+4;i++)
        printf("*");
Dan Oberlam
  • 2,435
  • 9
  • 36
  • 54
Zyad Sabry
  • 1
  • 1
  • 3

1 Answers1

0

when you have a character array as follows

char name[500];

You can take input a string that contains any character except \n as follows

int i;
for(i=0;(name[i]=getchar())!='\n';i++);
name[i]='\0';  //null termination

Assuming that the length of the array is enough to store the name.

Surajeet Bharati
  • 1,363
  • 1
  • 18
  • 36