Thread: Ascii Art program

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    4

    Ascii Art program

    Im new to C programming and am trying to complete a program for class which prints an array and then takes user input to make a picture out of 'X's. Right now Im just trying to create the part where it makes a straight line, however, im confused about calling functions and using arrays and was hoping some kind sole could give me a little help anything would be very much appreciated.

    here is what I have so far

    Code:
    #include<stdio.h>
    #include <string.h>
    #include <ctype.h>
    #define SIZE 25
    void Line(char array[25][25]);
    int main()
    {
    
    int row;
    int column;
    char array[SIZE][SIZE];
    
    //set array to space character
    for(row=0;row<SIZE;row++){
      for(column=0;column<SIZE;column++){
        array[row][column]=' ';
      }
    }
    //print out array (notice the brackets are here NOT in the set for loops)
    for(row=0;row<SIZE;row++){
      for(column=0;column<SIZE;column++){
        printf("[%c]",array[row][column]);
      }
      printf("\n");
    }
    
    Line(char array[SIZE][SIZE]);
    
    }
    
    
    
    
            
    void Line(char array[25][25])
    	{
    	int RowStart;
    	int ColStart;
    	int RowEnd;
    	int ColEnd;
    	int i;
    	int j;
    	
    	printf("Enter starting row: ");
    	scanf("%d\n", &RowStart);
    	printf("Enter starting column: ");
    	scanf("%d\n", &ColStart);
    	printf("Enter ending row: ");
    	scanf("%d\n", &RowEnd);
    	printf("Enter ending column: ");
    	scanf("%d\n", &ColEnd);
    	
    	for(i=RowStart; i<RowEnd; i++){
    	   for(j=ColStart; j<ColEnd; j++)
    	      printf("X", array[i][j]);
    	}
    	
    	}
    Thanks
    Last edited by brown; 04-12-2009 at 10:44 PM.

  2. #2
    Registered User
    Join Date
    Aug 2008
    Posts
    129
    I only see two problems (with something other than indentation). The first is on line 27:
    Code:
    Line(char array[SIZE][SIZE]);
    That's an array initialization inside the parens; it's a statement and not an expression. If your instructor hasn't defined these terms yet, I'm sure someone here has a very clear explanation (or a URL for one).

    Anyway, the long and short is that the identifier by itself is an expression, thus:
    Code:
    Line(array);
    The second mistake, although it won't directly affect the program, is on line 35 (and 5 for that matter):
    Code:
    void Line(char array[25][25])
    You can initialize an array like that within a function's body, but it has no extra effect in the header. You get the same thing as if you were to ask for "char **array"; it might be a square 25x25 matrix or it might not.

    By the way, I'm always better at answering questions (if I know the answers) than finding problems. But look out; if you find a question that really interests me, you might get more response than you expected.

    Oh, I almost forgot... Your file really needs indentation all over for the sake of readability. Even as short as it is, it's hard to follow without proper indentation as a guide.
    Last edited by Jesdisciple; 04-12-2009 at 11:24 PM.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    Quote Originally Posted by Jesdisciple View Post
    Code:
    void Line(char array[25][25])
    You can initialize an array like that within a function's body, but it has no extra effect in the header. You get the same thing as if you were to ask for "char **array";
    no, it is not...

    it is equivalent to
    Code:
    void Line(char array[][25])
    only one dimention could be left out when passing two-dimensional array...

    char** is not 2-dimentional array - it is pointer to pointer, it could though represent dynamically allocated array of pointers each of it points to one-dimentional array, but it cannot represent statically allocated 2-dimensional array

    Compiler will have no way to know how to access the array[i][j] member in this case

    in the case above - it will know that each line contains 25 chars, so it will skip i*25+j chars to get to the requested index
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  2. ASCII Art Decoder and Encoder
    By jessweetd in forum C Programming
    Replies: 7
    Last Post: 09-05-2004, 07:12 PM
  3. Checking ascii values of char input
    By yank in forum C Programming
    Replies: 2
    Last Post: 04-29-2003, 07:49 AM
  4. Results for the Encryption Contest -- June 23, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 07-07-2002, 08:04 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM