Thread: Rectangle

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

    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
    385
    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
    385
    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,817
    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
    385
    Than HK, made a perfect rectangle, thanx Tibo.

  7. #7
    Registered User
    Join Date
    Aug 2011
    Posts
    385
    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
    385
    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
    385
    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
    385
    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, 08: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, 06:10 PM
  5. Help With Rectangle,
    By incognito in forum Windows Programming
    Replies: 3
    Last Post: 03-30-2002, 12:43 PM