Thread: 2-dimensional array exercise!!!!!!!!!!!

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    3

    Exclamation 2-dimensional array exercise!!!!!!!!!!!

    Hi all, I am a newbie of C
    im doing my exercise about showing the edge like this
    0 0 0 0 0 0 0
    0 0 1 1 1 0 0
    0 1 0 0 0 1 0
    0 0 1 1 1 0 0
    0 0 0 0 0 0 0
    , and i got stuck w/ it. my code is:
    insert
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    void print ( int A[5][7] );
    main ()
    {
    	int A[5][7] = { { 0, 0, 0, 0, 0, 0, 0 } ,
    	{ 0, 0, 1, 1, 1, 0, 0 } ,
    	{ 0, 1, 0, 0, 0, 1, 0},
    	{ 0, 0, 1, 1, 1, 0 ,0 } ,
    	{ 0, 0, 0, 0, 0, 0, 0 } };
    	printf ("\nShowing the edge: \n");
    	print(A);
    	return EXIT_SUCCESS;
    }
    void print (int A[5][7])
    {
    	int x, y;
    	
    	for (x = 0; x < 5; x++){
    		for (y = 0; y < 7; y++)
    		A[x][y]= 0 ;
    		putchar ('\n');
    	}
    }

    could u guys put some comments about it? Did I miss some commands or sth like that??? Please help me

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    In the future, please don't use vague comments like “I got stuck with it.” Instead, you should explain things like the output you expect, the output you actually get, and so on. Be specific in describing the problem.

    In your case, your problem might be that your print() function isn't actually printing anything from the array. It sets each element to zero and prints a newline for each row. Is that what you wanted? Perhaps you should add a printf() instead of zeroing the array.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. two dimensional array
    By leisiminger in forum C Programming
    Replies: 12
    Last Post: 03-09-2008, 11:53 PM
  2. How To pass 2 dimensional array of strings to a function
    By chottachatri in forum C Programming
    Replies: 15
    Last Post: 01-25-2008, 02:20 PM
  3. Replies: 1
    Last Post: 04-25-2006, 12:14 AM
  4. Replies: 5
    Last Post: 11-20-2001, 12:48 PM