Thread: prototype of a function taking a pointer to interger array as a parameter

  1. #1
    Registered User
    Join Date
    Mar 2009

    prototype of a function taking a pointer to interger array as a parameter

    the error massage read as : " )" expected in the line of the prototype.
    and declararion terminated incorrectly.
    i 'm wondering where are the mistakes. thanks for help.
    the code is

    int total (int [] (*)); 
    int main()
    {int j,i;
      int [] (* ptr)[8]={
    		 {6,6,6,6,6,6,6,6} ,
    		 { 6,2,2,2,2,2,2,6,  } ,
    		 {6,3,1,0,1,1,2,7,   }  ,
    		 { 6,6,5,0,1,5,6,6,  }   ,
    		  {6,6,5,3,3,5,6,7,  }    ,
    		 { 7,6,5,3,2,6,6,7,  }   ,
    		 { 7,6,6,2,2,5,6,7, }    ,
    		 { 7,7,7,7,7,7,7,7,}    ,
    	      printf("%c",219) ;
    		 printf(" ");
    		   }   ;
    	     } ;
     return 0;
    int total(int [](*p))
    { int sum=0,i;
      return (sum/8);

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    in front of my computer
    What are you trying to do with this?
    int [] (* ptr)[8]
    besides this there are a lot of syntax errors in your program.
    Last edited by BEN10; 06-27-2009 at 06:41 AM.

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior

    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #3
    pwning noobs Zlatko's Avatar
    Join Date
    Jun 2009
    The Great White North

    In total, you are trying to pass in a pointer to the start of an array. You can use
    int total(int* p) if you want to access the array as you have done in your version with sum+=*(p+i), or you can declare total with int total(int p[]) and use sum += p[i]

    I think with int [] (* ptr)[8] you are trying to declare an array of pointers to arrays of 8 elements. Maybe there's a way to do that, but I'm used to simpler syntax. Try

    int ptr[][8] = 
    {6,6,6,6,6,6,6,6} ,
    This means you have an array of subarrays. Each subarray is 8 elements long, as specified by the 8. The first dimension does not need to be specified because the compiler will count up the number of subarrays you are specifying. If you did not have the initialization of ptr, then the first dimension would have to be specified.

    and call total(ptr[i]) in your loop as you are doing now.
    Then work on cleaning up the rest of your syntax errors.
    Last edited by Zlatko; 06-27-2009 at 07:02 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  3. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM