someone help me with my C program code(print square with string)

Status
Not open for further replies.

scandolous

Estimable
Dec 12, 2014
1
0
4,510
So I want to print out a square with certain # of rows composed of string characters, as opposed to stars. For example, if there're 5 rows, and the string was "ilikecake", it'd be
ilike
c a
k e
i l
ikeca

So far this is my code, but there're so many bugs.


#include <stdio.h>
#include <string.h>
void printSquare (char array[50], char word[50])
{
int i, j, n, counter;
printf ("enter the length (max 50):");
scanf ("%d", & n);

for (i=0; i<n; i++)
{
printf ("\n");
for (j=0; j<50; j++)
{
if (i==0 || i==n || j==0 || j==n-1)
{
if (counter > strlen(word)) counter =0
array[j]=word[counter++];
}

else
array[j]=' ';
}
}
}
}

void main () {
int choice, i,j;
char array[50][50];
char word[50]

printf ("enter string:");
scanf ("%s", &word);

printSquare(array, word);
for (i=0; i<50; i++)
{
for (j=0; j<50; j++)
{
printf ("%c", array[j]);
}
printf ("\r\n");
}
}

I really need to finish this assignment. Thanks for your help.
 
Status
Not open for further replies.