Thread: Determinant Calculation Program.... HELP PLZ

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well did you call it 3 times?
    read( mat1, n, fp );
    read( mat2, n, fp );
    read( mat3, n, fp );
    ?
    You're not returning n.

    By the way, n should be a local variable. It's useless as a parameter.
    Code:
    void read(double a[N][N], FILE* inp)
    
    {
    	int i,j,n;
    	fscanf(inp,"%d", &n);
    	for (i=0; i<n; i++)
    	{ 
    		for (j=0;j<n;j++)
    		fscanf(inp, "%lf", &a[i][j]);			
    	}
        return n;
    }
    Then
    n1 = read( mat1, fp );
    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.

  2. #17
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    How many times do you call this new read function of yours ?

    EDIT : Beaten to the punch
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #18
    Registered User ss7's Avatar
    Join Date
    Nov 2006
    Location
    T.O., Canada
    Posts
    11
    hm ok, I just replaced the read function with the code above and it gave me errors:

    c:19: warning: `return' with a value, in function returning void
    c:54: warning: passing arg 2 of `read' makes pointer from integer without a cast
    c:54: too many arguments to function `read'

    So if Im inputing from a single txt file that contains data of 3 matrices, I still have to call read function 3 times in the main?

    PS. Also the thing I noticed if I include the fscanf in the read function to read n, it wont read the n which is the first value but rather the first element of the matrix row.
    Last edited by ss7; 11-29-2006 at 06:19 PM.

  4. #19
    Registered User ss7's Avatar
    Join Date
    Nov 2006
    Location
    T.O., Canada
    Posts
    11
    anyone?

  5. #20
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    # 1 Don't bump up your threads.

    # 2 your function is declared as void, yet it returns an int. So it should be declared to return an int. That's sort of Salem's bad. But I don't think he expected you to copy and paste the code. Further, Salem's function takes in a FILE *, whereas you're probably sending it an int. Bad news. Lastly, your original function took 3 arguments. Salem's takes 2. I've noted this error in your code before. By now you should know that when your compiler complains about "too many arguments to function foo" it means that you're sending too many arguments to function foo...
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  6. #21
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > c:19: warning: `return' with a value, in function returning void
    So make it return something

    void read(double a[N][N], FILE* inp)
    becomes
    int read(double a[N][N], FILE* inp)

    Simple innit?
    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. Need help with basic calculation program.
    By StateofMind in forum C Programming
    Replies: 18
    Last Post: 03-06-2009, 01:44 AM
  2. Program calculation problems?
    By rebel in forum C++ Programming
    Replies: 7
    Last Post: 11-28-2005, 03:31 PM
  3. Wages Calculation Program
    By DrKillPatient in forum C++ Programming
    Replies: 2
    Last Post: 10-18-2005, 07:06 AM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM