I got this code from a book I bought. I wanted to see if it words but it gives me errors.

Here is the source code.

#include<math.h>
#define NRANSI
#include"nrutil.h"
#define SWAP(a,b)
{
    temp=(a);(a)=(b);(b)=temp;
}

void gaussj(float **a, int n, float **b, int m)

{
    
    int *indxc,*indxr,*ipiv;
    int i,icol,irow,j,k,l,ll;
    float big,dum,pivinv,temp;
    indxc=ivector(1,n);
    indxr=ivector(1,n);
    ipiv=ivector(1,n);
    for (j=1;j<=n;j++) ipiv[j]=0;
    for (i=1;i<=n;i++)
    {
        
        big=0.0;
        for (j=1;j<=n;j++)
        if (ipiv[j] != 1)
        for (k=1;k<=n;k++)
        {
            
            if (ipiv[k] == 0)
            {
                
                if (fabs(a[j][k]) >= big)
                {
                    
                    big=fabs(a[j][k]);
                    irow=j;
                    icol=k;
                    
                }
                
                
            }
            else if (ipiv[k] > 1) nrerror("gaussj: Singular Matrix-1");
            
        }
        
        ++(ipiv[icol]);
        if (irow != icol)
        {
            
            for (l=1;l<=n;l++) SWAP(a[irow][l],a[icol][l])
            for (l=1;l<=m;l++) SWAP(b[irow][l],b[icol][l])
            
        }
        
        indxr[i]=irow;
        indxc[i]=icol;
        if (a[icol][icol] == 0.0) nrerror("gaussj: Singular Matrix-2");
        pivinv=1.0/a[icol][icol];
        a[icol][icol]=1.0;
        for (l=1;l<=n;l++) a[icol][l] *= pivinv;
        for (l=1;l<=m;l++) b[icol][l] *= pivinv;
        for (ll=1;ll<=n;ll++)
        if (ll != icol)
        {
            
            dum=a[ll][icol];
            a[ll][icol]=0.0;
            for (l=1;l<=n;l++) a[ll][l] -= a[icol][l]*dum;
            for (l=1;l<=m;l++) b[ll][l] -= b[icol][l]*dum;
            
        }
        
        
    }
    
    for (l=n;l>=1;l--)
    {
        
        if (indxr[l] != indxc[l])
        for (k=1;k<=n;k++)
        SWAP(a[k][indxr[l]],a[k][indxc[l]]);
        
    }
    
    free_ivector(ipiv,1,n);
    free_ivector(indxr,1,n);
    free_ivector(indxc,1,n);
    
}

#undef SWAP
#undef NRANSI

and the header file:

#ifndef _NR_UTILS_H_
#define _NR_UTILS_H_
staticfloat sqrarg;
#define SQR(a) ((sqrarg=(a)) == 0.0 ? 0.0 : sqrarg*sqrarg)
staticdouble dsqrarg;
#define DSQR(a) ((dsqrarg=(a)) == 0.0 ? 0.0 : dsqrarg*dsqrarg)
staticdouble dmaxarg1,dmaxarg2;
#define DMAX(a,b) (dmaxarg1=(a),dmaxarg2=(b),(dmaxarg1) > (dmaxarg2) ?\
(dmaxarg1) : (dmaxarg2))
staticdouble dminarg1,dminarg2;
#define DMIN(a,b) (dminarg1=(a),dminarg2=(b),(dminarg1) < (dminarg2) ?\
(dminarg1) : (dminarg2))
staticfloat maxarg1,maxarg2;
#define FMAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1) > (maxarg2) ?\
(maxarg1) : (maxarg2))
staticfloat minarg1,minarg2;
#define FMIN(a,b) (minarg1=(a),minarg2=(b),(minarg1) < (minarg2) ?\
(minarg1) : (minarg2))
staticlong lmaxarg1,lmaxarg2;
#define LMAX(a,b) (lmaxarg1=(a),lmaxarg2=(b),(lmaxarg1) > (lmaxarg2) ?\
(lmaxarg1) : (lmaxarg2))
staticlong lminarg1,lminarg2;
#define LMIN(a,b) (lminarg1=(a),lminarg2=(b),(lminarg1) < (lminarg2) ?\
(lminarg1) : (lminarg2))
staticint imaxarg1,imaxarg2;
#define IMAX(a,b) (imaxarg1=(a),imaxarg2=(b),(imaxarg1) > (imaxarg2) ?\
(imaxarg1) : (imaxarg2))
staticint iminarg1,iminarg2;
#define IMIN(a,b) (iminarg1=(a),iminarg2=(b),(iminarg1) < (iminarg2) ?\
(iminarg1) : (iminarg2))
#define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))
#ifdefined(__STDC__) || defined(ANSI) || defined(NRANSI) /* ANSI */
void nrerror(char error_text[]);
float *vector(long nl, long nh);
int *ivector(long nl, long nh);
unsignedchar *cvector(long nl, long nh);
unsignedlong *lvector(long nl, long nh);
double *dvector(long nl, long nh);
float **matrix(long nrl, long nrh, long ncl, long nch);
double **dmatrix(long nrl, long nrh, long ncl, long nch);
int **imatrix(long nrl, long nrh, long ncl, long nch);
float **submatrix(float **a, long oldrl, long oldrh, long oldcl, long oldch,
long newrl, long newcl);
float **convert_matrix(float *a, long nrl, long nrh, long ncl, long nch);
float ***f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh);
void free_vector(float *v, long nl, long nh);
void free_ivector(int *v, long nl, long nh);
void free_cvector(unsignedchar *v, long nl, long nh);
void free_lvector(unsignedlong *v, long nl, long nh);
void free_dvector(double *v, long nl, long nh);
void free_matrix(float **m, long nrl, long nrh, long ncl, long nch);
void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch);
void free_imatrix(int **m, long nrl, long nrh, long ncl, long nch);
void free_submatrix(float **b, long nrl, long nrh, long ncl, long nch);
void free_convert_matrix(float **b, long nrl, long nrh, long ncl, long nch);
void free_f3tensor(float ***t, long nrl, long nrh, long ncl, long nch,
long ndl, long ndh);
#else/* ANSI */
/* traditional - K&R */
void nrerror();
float *vector();
float **matrix();
float **submatrix();
float **convert_matrix();
float ***f3tensor();
double *dvector();
double **dmatrix();
int *ivector();
int **imatrix();
unsignedchar *cvector();
unsignedlong *lvector();
void free_vector();
void free_dvector();
void free_ivector();
void free_cvector();
void free_lvector();
void free_matrix();
void free_submatrix();
void free_convert_matrix();
void free_dmatrix();
void free_imatrix();
void free_f3tensor();
#endif/* ANSI */
#endif/* _NR_UTILS_H_ */

The errors I keep on getting is:

1>Linking...
1>gaussj.obj : error LNK2019: unresolved external symbol _free_ivector referenced in function _gaussj
1>gaussj.obj : error LNK2019: unresolved external symbol _nrerror referenced in function _gaussj
1>gaussj.obj : error LNK2019: unresolved external symbol _ivector referenced in function _gaussj
1>LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Documents\Visual Studio 2005\Projects\Linear Equation\Debug\Linear Equation.exe : fatal error LNK1120: 4 unresolved externals

>> for (j=1;j&lt;=n;j++)

I think you misquoted the code (lines 19 and 20) because that is just so much nonsense. Proofread the code you have to make sure you did not make typing errors. If its really like that in the book then go to the publishers web site to see if they have a list of book corrections or electronic copy of the code, which sometimes has corrected code.

actually that is the actual code, it came with cd in which i opened and copied pasted. :) thanks for editing my post.

actually that is the actual code, it came with cd in which i opened and copied pasted. :) thanks for editing my post.

Looks to me like Daniweb parsed the greater and less than into html entities or you accidentally copied and pasted from a html document on the CD.

Comments
B I N G O!

>> for (j=1;j&lt;=n;j++)

I think you misquoted the code (lines 19 and 20) because that is just so much nonsense. Proofread the code you have to make sure you did not make typing errors. If its really like that in the book then go to the publishers web site to see if they have a list of book corrections or electronic copy of the code, which sometimes has corrected code.

Um, it is fairly obvious that your online parser has a flaw and it not converting &lt (html syntax into plain text ">"). You shouldn't blame the OP for your mistakes Ancient Dragon. And why is my infraction that you mistakenly gave me still there, did I not ask you to get rid of it:)

I did say this before!

Um, it is fairly obvious that your online parser has a flaw and it not converting &lt (html syntax into plain text ">"). You shouldn't blame the OP for your mistakes Ancient Dragon.

Its not an error -- to my knowledge (and I could be wrong) the only markup codes recognized are code tags. People are supposed to post ONLY code -- this is not a place to test html code. If someone wants to post C or C++ code that contains html markup code then its his respoinsibility to remove it.

And why is my infraction that you mistakenly gave me still there, did I not ask you to get rid of it:)

That was no mistake -- it was intentional.

I did say this before!

Oh. I didn't realize Dani made you Super Mod.

Does anyone bother to actually read my posts these days, cos I find I am just repeating myself.

Ancient Dragon, your online code beautifier is flawed!


It changes all the "< >" symbols to &lt and &gt respectively! So telling the op of for experimenting with html is silly, It is YOUR fault.
.

>That was no mistake -- it was intential.
I already told you, it was a mistake, I forgot to add the code tags and then was cut off the internet so I was unable to edit my post in time. Why should I be punished for a mistake?

:'(

You promised me you would tell the supermods, but you never did :(

Does anyone bother to actually read my posts these days, cos I find I am just repeating myself.

Ancient Dragon, your online code beautifier is flawed!


It changes all the "< >" symbols to &lt and &gt respectively! So telling the op of for experimenting with html is silly, It is YOUR fault.
.

Ah, my mistake. I though you meant the other way around. If there is a problem you should report it in the Community Feedback board. But I have not seen that in any other posts.

this is a test of html markup parsor for < and > symbol also together like this <>

As you can see it works great for me. Sometimes the parser turns things into smiley faces, but there is a check box to turn off smileys in text posts.

>That was no mistake -- it was intential.
I already told you, it was a mistake, I forgot to add the code tags and then was cut off the internet so I was unable to edit my post in time. Why should I be punished for a mistake?:'(

Another case of miscommunication.

>You promised me you would tell the supermods, but you never did :(

Send me the PM or link where I made that statement because I don't remember it. This is something I think would be better discussed via PM instead of here.

>If there is a problem you should report it in the Community Feedback board. But I have not seen that in any other posts.

What has this got to do with the daniweb community feedback? Your online code beautifier is the thing that's broken. (Why am I repeating myself again?)

>As you can see it works great for me.

That's great, we all know the daniweb code tagging works fine. But what has this got to do with the online beautifier you are using which is broken?

>This is something I think would be better discussed via PM instead of here.

What is there to discuss. For the time being I will pretend it didn't happen. Please just don't make these mistakes in the future. Be careful with that infraction button you use. Thanx. :)

Just in case you didn't get it. I'm going to say it again.

YOUR ONLINE BEAUTIFIER IS BROKE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Um, it is fairly obvious that your online parser has a flaw

>If there is a problem you should report it in the Community Feedback board. But I have not seen that in any other posts.

What has this got to do with the daniweb community feedback? Your online code beautifier is the thing that's broken. (Why am I repeating myself again?)

>As you can see it works great for me.

That's great, we all know the daniweb code tagging works fine. But what has this got to do with the online beautifier you are using which is broken?

The reason you have to keep repeating yourself if because you fail to explain what you mean the first time. Yes, you are correct that the problem is that beautifier program. With a little more testing I see that the problem does not occur when I check the "Skip HTML, give me plain code! (Use Save-As function of your browser) " checkbox.

>>This is something I think would be better discussed via PM instead of here.

What is there to discuss. For the time being I will pretend it didn't happen. Please just don't make these mistakes in the future. Be careful with that infraction button you use. Thanx. :)

I will repeat myself again :) That infraction was no mistake -- when you forget to use code tags hit the Edit button and correct it. Anyone with as many posts as you have should know better.

>The reason you have to keep repeating yourself if because you fail to explain what you mean the first time.

How much more clearer can I put it? "Sigh" :)

>when you forget to use code tags hit the Edit button and correct it.

I got cut off from the net and couldn't edit it in time. Yet again I stated this previously. Oh dear, Ancient Dragon, you are hard work!!! He he.

>Oh dear, Ancient Dragon, you are hard work!!! He he.

Old people have a right to be :) Would like to continue this but have to go to work now.

This article has been dead for over six months. Start a new discussion instead.