Thread: No square displays

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688

    No square displays

    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");
         }
    }
    Double Helix STL

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    "% c" is not a valid format. " %c" is, though.

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Thank you tabstop
    Double Helix STL

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Use gcc with the appropriate option to tell you about format strings perhaps?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loop seg error
    By Zishaan in forum Game Programming
    Replies: 2
    Last Post: 03-28-2007, 01:27 PM
  2. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  3. Help with my draughts game
    By Zishaan in forum C++ Programming
    Replies: 9
    Last Post: 03-24-2007, 07:33 AM
  4. I Need To Know Some Things That I Can Put Into A Batch File
    By TheRealNapster in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-20-2003, 08:12 PM
  5. Dos commands hehe
    By Carp in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-17-2003, 02:51 PM