Hey guys.
I am having a problem making the square of characters appear at the end of the program. It compiles fine, but I get no output after input.
Any reason why?
I have accounted for the extra character in scanf() but it seems the program is totally ignoring the "let" char passed to it. I know the square "is" being drawn as to where the cursor is in the output, but the fill character is not being shown at all and I am getting no square.
This is my code, any help appriciated.
Code:#include <stdio.h> /*function prototype*/ void printSquare ( int, char ); /*main function - driver **/ int main ( int argc, char *argv[] ) { int sideValue = 0; char filler = '\0'; puts("Enter a side value:"); scanf("%d", &sideValue); puts("Enter a single character:"); scanf("% c", &filler); printf("\n"); printSquare( sideValue, filler ); getchar(); /*freeze console output*/ getchar(); return 0; /*return value from int main()*/ } /*function to print a solid square of the character size based on the value passed*/ void printSquare ( int x, char let ) { getchar(); int i, j; for ( i = 1; i <= x; i++ ) { for ( j = 1; j <= x; j++ ) printf("%c", let); printf("\n"); } }



LinkBack URL
About LinkBacks


