Trouble producing horizontal lines for grid box

This is a discussion on Trouble producing horizontal lines for grid box within the C Programming forums, part of the General Programming Boards category; Hi guys. This has been really frustrating not only because I have been trying many times but also this project ...

  1. #1
    Registered User hungrymouth's Avatar
    Join Date
    Oct 2012
    Posts
    19

    Trouble producing horizontal lines for grid box

    Hi guys. This has been really frustrating not only because I have been trying many times but also this project is due monday and I really need to get this project right to pass the class.

    The problem is that I am trying to produce a grid box but I can't seem to get the horizontal lines right! Not only am I having problems with that but since this grid box does not have fixed values, my professor will be changing the values of the variables to see that it works for every number to generate a grid box!
    (I currently have it as 5(Row),6(Col),4(SizeX),4(SizeY),12(Color) so my professor can change it to lets say 3,2,6,7,5
    the only values that are fixed is the grid size which is 3 x 1 per every cell

    But for now I want to work with the current numbers I have since I am using graphing paper to guide me.
    My corners are working fine it's just the horizontal lines that I can't seem to fix! Correct me if I'm wrong but I'm pretty sure my problem lies in the settextposition. Also I have attached t photos just for you guys to see that the code I posted produces exactly what I want is 4 x 4 box but then when I change the values of the variables the corners stay good but the horizontal lines do not go along with the corners.Name:  boxcorrect.png
Views: 338
Size:  56.0 KBName:  boxcorrect.png
Views: 315
Size:  32.6 KB

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #include "Myhead.h"
    #include "notes28.h"
    
    int main()
    {
      //  Heading();
        ClearTheScreen();
       
        GridBox(5,6,4,4,12);   
    
        PauseTheScreen();
    }
    
    
    
    void GridBox(int Row,int Col,int SizeX, int SizeY, int Color)
    {
        int q,k,m;
        char UpperLeft[2],UpperRight[2],LowerLeft[2],LowerRight[2];
        char Vertical[2],Horizontal[2];
        char UpperTee[2],LowerTee[2],LeftTee[2],RightTee[2];
        char Cross[2];
    
        _settextcolor(Color);
    
        UpperLeft [0] = 218;
        UpperRight[0] = 191;
        LowerLeft [0] = 192;
        LowerRight[0] = 217;
        Vertical  [0] = 179;
        Horizontal[0] = 196;
    
        UpperTee[0] = 194;
        LowerTee[0] = 193;
        LeftTee [0] = 195;
        RightTee[0] = 180;
        Cross   [0] = 197;
    
    
        UpperLeft [1] = '\0';
        UpperRight[1] = '\0';
        LowerLeft [1] = '\0';
        LowerRight[1] = '\0';
        Vertical  [1] = '\0';
        Horizontal[1] = '\0';
    
         
        UpperTee  [1] = '\0';
        LowerTee  [1] = '\0';
        LeftTee   [1] = '\0';
        RightTee  [1] = '\0';
        Cross     [1] = '\0';
    
    
        // CORNERS
        _settextposition(Row,Col);
        _outtext(UpperLeft);
        _settextposition(Row,Color+Row+SizeX+1);
        _outtext(UpperRight);
        _settextposition(Color+1,Col);
        _outtext(LowerLeft);
        _settextposition(Color+1,Color+Row+SizeX+1);
        _outtext(LowerRight);
    
        // Horizontal Lines
        for ( q = 0; q < Row; q++)
        {
           for ( k = 0; k < SizeX; k++)
           {
              for ( m = 0; m < 3; m++)
              {
                 _settextposition(Row+2*q,1+Col+SizeX*k+m);
                 _outtext(Horizontal);
              }
           }
        }
    
    }

  2. #2
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    I glanced through this. I wanted to compile it but I don't know what Myhead.h or notes28.h are. Could you include these files for anyone who might want to compile a working example of your program?

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Trouble with for loop to create 5x4 grid box
    The interface to your function has changed in the last week.

    It seems to me that you need to do two things.

    1. You need to call _settextposition() once for each row.
    That is, if you want to output "abc" next to each other, then you can just call
    _outtext("a");_outtext("b");_outtext("c");
    You don't need to do
    _settextposition(y,x);_outtext("a");
    _settextposition(y,x+1);_outtext("b");
    _settextposition(y,x+2);_outtext("c");


    2. Do the 4 corners last rather than first.
    By doing this, all the rows and columns are identical. This will greatly simplify the code you use to generate the main grid.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User hungrymouth's Avatar
    Join Date
    Oct 2012
    Posts
    19
    Oops sorry forgot to include myhead.h but notes28.h is the code I just put there let me do it seperately so you call compile it from the calling program


    Code:
     // this is the calling program
    #include <stdio.h>
    #include <stdlib.h>
     #include "notes28.h"
    
     
    int main()
    {
      //  Heading();
        ClearTheScreen();
        
        GridBox(5,6,4,4,12);   
     
        PauseTheScreen();
    }

    Code:
     //source code
     
    void GridBox(int Row,int Col,int SizeX, int SizeY, int Color)
    {
        int q,k,m;
        char UpperLeft[2],UpperRight[2],LowerLeft[2],LowerRight[2];
        char Vertical[2],Horizontal[2];
        char UpperTee[2],LowerTee[2],LeftTee[2],RightTee[2];
        char Cross[2];
     
        _settextcolor(Color);
     
        UpperLeft [0] = 218;
        UpperRight[0] = 191;
        LowerLeft [0] = 192;
        LowerRight[0] = 217;
        Vertical  [0] = 179;
        Horizontal[0] = 196;
     
        UpperTee[0] = 194;
        LowerTee[0] = 193;
        LeftTee [0] = 195;
        RightTee[0] = 180;
        Cross   [0] = 197;
     
     
        UpperLeft [1] = '\0';
        UpperRight[1] = '\0';
        LowerLeft [1] = '\0';
        LowerRight[1] = '\0';
        Vertical  [1] = '\0';
        Horizontal[1] = '\0';
     
          
        UpperTee  [1] = '\0';
        LowerTee  [1] = '\0';
        LeftTee   [1] = '\0';
        RightTee  [1] = '\0';
        Cross     [1] = '\0';
     
     
        // CORNERS
        _settextposition(Row,Col);
        _outtext(UpperLeft);
        _settextposition(Row,Color+Row+SizeX+1);
        _outtext(UpperRight);
        _settextposition(Color+1,Col);
        _outtext(LowerLeft);
        _settextposition(Color+1,Color+Row+SizeX+1);
        _outtext(LowerRight);
     
        // Horizontal Lines
        for ( q = 0; q < Row; q++)
        {
           for ( k = 0; k < SizeX; k++)
           {
              for ( m = 0; m < 3; m++)
              {
                 _settextposition(Row+2*q,1+Col+SizeX*k+m);
                 _outtext(Horizontal);
              }
           }
        }
     
    }
    i removed the myhead.h since its not really necessary it was just the header

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with for loop to create 5x4 grid box
    By hungrymouth in forum C Programming
    Replies: 1
    Last Post: 11-28-2012, 08:41 AM
  2. trouble with the tic tac toe grid
    By shruthi in forum C Programming
    Replies: 2
    Last Post: 02-01-2012, 01:01 AM
  3. Trouble moving lines up in 2D array
    By powell5487 in forum C Programming
    Replies: 5
    Last Post: 03-03-2009, 11:54 AM
  4. Looping trouble - Spitting out too many lines at once
    By Venicia in forum C++ Programming
    Replies: 2
    Last Post: 05-15-2007, 04:45 PM
  5. no horizontal scroll bar?
    By scott27349 in forum C++ Programming
    Replies: 0
    Last Post: 03-16-2002, 09:41 PM

Tags for this Thread


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