Rectangle

This is a discussion on Rectangle within the C Programming forums, part of the General Programming Boards category; Can someone please correct this code to display a perfect rectangle. It displays a stupid kind of rectangle... Code: #include<stdio.h> ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    384

    Rectangle

    Can someone please correct this code to display a perfect rectangle. It displays a stupid kind of rectangle...

    Code:
    #include<stdio.h>
    int main()
    {
    		char c,i;
    		
    		c=169;
    		printf("%c",c);
    		c=196;
    		for(i=0;i<=2;i++)
    			printf("%c",c);
    		c=170;
    		printf("%c\n",c);
    		
    		c=179;
    		printf("%c",c);
    		printf("   ");
    		printf("%c\n",c);
    		c=192;
    		printf("%c",c);
    		c=196;
    		for(i=0;i<=2;i++)
    			printf("%c",c);
    		c=217;
    		printf("%c",c);
    		
                     return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2011
    Location
    Denmark
    Posts
    80
    Hi,

    Is you only want to display a rectangle I think one printf like printf(" _________\n|_________|\n"); would be enough. But do you want to display some special char? What are those values that you're assigning to c? Also when you do a "for" loop it is better to use an int and not a char.

  3. #3
    Registered User
    Join Date
    Aug 2011
    Posts
    384
    Quote Originally Posted by Tibo-88 View Post
    Hi,

    Is you only want to display a rectangle I think one printf like printf(" _________\n|_________|\n"); would be enough. But do you want to display some special char? What are those values that you're assigning to c? Also when you do a "for" loop it is better to use an int and not a char.
    Sorry for the int i (my bad), doesn't make any difference though, and thanks for the rectangle you suggested, its better than mine, but still it's got sides which are fragmented, I need a perfect rectangle without using the standard rectangle function.

  4. #4
    Registered User
    Join Date
    Aug 2011
    Posts
    384
    Tried this...

    Code:
    #include<stdio.h>
    int main()
    {
    		char c;
    
    		printf(" _________\n");
    		c=179;	
    		printf("%c",c);
    		printf("_________%c\n",c);
                    return 0;
    }
    But still the corners are distorted....

    Is it even possible to draw a perfect rectangle, manually....

  5. #5
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,801
    Your corners (upper left/right) should be 218/191 not 169/170.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  6. #6
    Registered User
    Join Date
    Aug 2011
    Posts
    384
    Than HK, made a perfect rectangle, thanx Tibo.

  7. #7
    Registered User
    Join Date
    Aug 2011
    Posts
    384
    I wanna append a rectangle at the end of the pattern formed by compiling the following code, but the cursor is at the bottom right corner. Is there any way to bring the cursor back to the first line, without using any standard function.



    Code:
    #include<stdio.h>
    
    
    
    void main()
    {
    		char c,i;
    
    		c=218;
    		printf("%c",c);
    		c=196;
    		for(i=0;i<=2;i++)
    			printf("%c",c);
    		c=191;
    		printf("%c\n",c);
    		
    		c=179;
    		printf("%c",c);
    		printf("   ");
    		printf("%c",c);
    
    		c=175;
    		printf("%c",c);
    		c=45;
    		printf("%c%c%c",c,c,c);
    		c=62;
    		printf("%c\n",c);
    
    		c=192;
    		printf("%c",c);
    		c=196;
    		for(i=0;i<=2;i++)
    			printf("%c",c);
    		c=217;
    		printf("%c",c);
    	
    }
    Last edited by juice; 10-27-2011 at 06:51 AM.

  8. #8
    Registered User
    Join Date
    Aug 2011
    Posts
    384
    Is there any function or any other way to move the cursor...

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Include conio.h and you can use gotoxy(x,y), where x=column and y=row,

    or

    include windows.h and use SetConsoleCursorPosition(coordinate), where coordinate is a struct with two ints - x and y.

    Do a search on the forum, and you'll find examples of both.

  10. #10
    Registered User
    Join Date
    Aug 2011
    Posts
    384
    Quote Originally Posted by Adak View Post
    Include conio.h and you can use gotoxy(x,y), where x=column and y=row,
    Trying to use gotoxy by including conio.h, but it says
    " 'gotoxy': identifier not found "

    any suggestions...

  11. #11
    Registered User
    Join Date
    Aug 2011
    Posts
    384
    Plz help....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rectangle class
    By blackant in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2009, 08:33 AM
  2. rectangle of asterisks
    By sugeknight in forum C++ Programming
    Replies: 1
    Last Post: 02-02-2009, 07:46 PM
  3. Rectangle
    By Vicious in forum Windows Programming
    Replies: 3
    Last Post: 06-03-2002, 10:15 PM
  4. rectangle
    By Unregistered in forum Game Programming
    Replies: 7
    Last Post: 04-06-2002, 05:10 PM
  5. Help With Rectangle,
    By incognito in forum Windows Programming
    Replies: 3
    Last Post: 03-30-2002, 11:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21