Thread: Why is this an invalid syntax

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    83

    Why is this an invalid syntax

    float detrminant(float[][], float);

    I'm using python.

  2. #2
    Registered User
    Join Date
    Feb 2015
    Posts
    83
    I'm just trying to find the inverse of a matrix and before it even runs the code it says that I have an invalid syntax with this line.

    Code:
    #include<stdio.h>
    #include<math.h>
    
    float detrminant(float[][], float);
     
    void cofactors(float[][], float);
     
    void trans(float[][], float[][], float);
     
    main() {

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Only the left-most [] can be empty.
    All the others need the actual size of the corresponding minor dimension of the array you want to pass in.
    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.

  4. #4
    Registered User
    Join Date
    Feb 2015
    Posts
    83
    so by putting
    Code:
    #include<stdio.h>
    #include<math.h>
    float detrminant (float[][25], float);
     
    void cofactors(float[][], float);
     
    void trans(float[][], float[][], float);
     
    main() {
    it should work

  5. #5
    Registered User
    Join Date
    Feb 2015
    Posts
    83
    They are empty because the user needs to define the size of the matrix

  6. #6
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Quote Originally Posted by ashley1nonly View Post
    They are empty because the user needs to define the size of the matrix
    If this is true then why not have the user input the size and then pass this data to the function as an argument into the parameter? You may be confusing C syntax with Python (never used it, so don't know for sure). In this concept, you would not have empty indexes for the array within the parameter list as the value is already present.
    Double Helix STL

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > They are empty because the user needs to define the size of the matrix
    How?

    If you're using C99, then this would work for arrays that will fit on the stack.
    Code:
    #include <stdio.h>
    #include <string.h>
    
    void foo ( int size, char arr[][size] ) {
      for ( int i = 0 ; i < size ; i++ ) {
        printf("%s\n", arr[i] );
      }
    }
    
    int main ( ) {
      int size = 10;  // get this from the user
      char arr[size][size];
      for ( int i = 0 ; i < size ; i++ ) {
        sprintf(arr[i],"Line %d",i);
      }
      foo(size,arr);
      return 0;
    }
    But if you want really large arrays, then using malloc is your only choice, and the [][] syntax no longer applies.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array Syntax Versus Pointer Syntax
    By LyTning94 in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2011, 10:56 AM
  2. invalid input
    By Ji33my in forum C++ Programming
    Replies: 19
    Last Post: 09-24-2010, 11:25 AM
  3. Invalid conversions
    By gr8npwrfl in forum C Programming
    Replies: 4
    Last Post: 07-29-2008, 02:11 PM
  4. Invalid name?
    By rabbit in forum C++ Programming
    Replies: 4
    Last Post: 03-01-2006, 08:02 PM
  5. Why is this invalid?
    By sand_man in forum C Programming
    Replies: 1
    Last Post: 10-20-2004, 10:51 PM

Tags for this Thread