Thread: fatal error

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    4

    fatal error

    hello!

    i cant find the problem, please help me
    the errors:POLINK: error:

    Unresolved external symbol '_printA'.
    POLINK: error: Unresolved external symbol '_printO'.
    POLINK: fatal error: 2 unresolved external(s).

    Code:
    #include <stdio.h>
    #include <math.h>
    
    void scaling(double* P[],double B[], int i,  int j,int order);
    
    void PrintA(double A[30][30], int m,int n);
    
    void PrintO(double* O[30], double B[30],int m,int n);
    
    
    int main()
    {
        double A[30][30];
        double B[30];
        double* O[30];
        int i,j,m,n,order;
    
    printf("enter the number of rows and columns: \n");
    scanf("%d%d",&i,&j);
    printf("enter %d*%d matrix\n:",i,j);
    
    for (m=0 ; m<i ; m++)
        for(n=0 ; n<j ; n++)
            scanf("%lf",&(A[m][n]));
    
    printf("enter %d vector: \n",i);
    
    for (m=0 ; m<i ; m++)
    scanf("%lf",&(B[m]));
     
    for(order=0;order<i;order++);
    {
    	scaling(O,B,i,j,order);
    	printA(A,i,j);
    	printO(O,B,i,j);
    }
    	return 0;
    }
    
    void scaling(double* P[],double B[], int i,  int j,int order)
    {
    int m,n,maxrow;
    double max[30], maxi=0,temp2;
    double* temp;
        for (m=order;m<i;m++)
            for(n=order;n<j && fabs(P[m][n])>max[m];n++)
                           max[m]=fabs(P[m][n]);
    for (m=order;m<i;m++)
    	if ((fabs(P[m][order])/max[m])>maxi)
    		{
    		maxi=(fabs(P[m][order]/max[m]));
    		maxrow=m;
    		}
    if(maxrow!=order)
            {
                temp=P[maxrow];
                P[maxrow]=P[order];
                P[order]=temp;
    
                temp2=B[maxrow];
                B[maxrow]=B[order];
                B[order]=temp2;
    
            }
    
    }
    
    void PrintA(double A[30][30], int m,int n)
    {
    	int i,j;
    
    	printf("original coefficients matrix:\n");
    	for(i=0;i<m;i++)
    	{
    		for(j=0;j<n;j++)
    			printf("%.2lf ",A[i][j]);
    
    		printf("\n");
    	}
    	printf("\n");
    }
    
    void PrintO(double* O[30], double B[30], int m,int n)
    {
    	int i,j;
    
    	printf("current matrix:\n");
    	for(i=0;i<m;i++)
    	{
    		for(j=0;j<n;j++)
    			printf("%.2lf ",O[i][j]);
    		printf("| %.2lf",B[i]);
    		printf("\n");
    	}
    	printf("\n");
    }
    thank!

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    printA is different from PrintA, and similarly printO is different from PrintO.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    4

    tanks now i have a run time error

    hello' thank you for the answer!
    i have a run time error now....
    it stops when it spouse to print marix O.
    Code:
    #include <stdio.h>
    #include <math.h>
    
    void scaling(double* P[],double B[], int i,  int j,int order);
    
    void printA(double A[30][30], int m,int n);
    
    void printO(double* O[30], double B[30],int m,int n);
    
    
    int main()
    {
        double A[30][30];
        double B[30];
        double* O[30];
        int i,j,m,n,order;
    
    printf("enter the number of rows and columns: \n");
    scanf("%d%d",&i,&j);
    printf("enter %d*%d matrix\n:",i,j);
    
    for (m=0 ; m<i ; m++)
        for(n=0 ; n<j ; n++)
            scanf("%lf",&(A[m][n]));
    
    printf("enter %d vector: \n",i);
    
    for (m=0 ; m<i ; m++)
    scanf("%lf",&(B[m]));
     
    for(order=0;order<i;order++);
    {
    	scaling(O,B,i,j,order);
    	printA(A,i,j);
    	printO(O,B,i,j);
    }
    	return 0;
    }
    
    void scaling(double* P[],double B[], int i,  int j,int order)
    {
    int m,n,maxrow;
    double max[30], maxi=0,temp2;
    double* temp;
        for (m=order;m<i;m++)
            for(n=order;n<j && fabs(P[m][n])>max[m];n++)
                           max[m]=fabs(P[m][n]);
    for (m=order;m<i;m++)
    	if ((fabs(P[m][order])/max[m])>maxi)
    		{
    		maxi=(fabs(P[m][order]/max[m]));
    		maxrow=m;
    		}
    if(maxrow!=order)
            {
                temp=P[maxrow];
                P[maxrow]=P[order];
                P[order]=temp;
    
                temp2=B[maxrow];
                B[maxrow]=B[order];
                B[order]=temp2;
    
            }
    
    }
    
    void printA(double A[30][30], int m,int n)
    {
    	int i,j;
    
    	printf("original coefficients matrix:\n");
    	for(i=0;i<m;i++)
    	{
    		for(j=0;j<n;j++)
    			printf("%.2lf ",A[i][j]);
    
    		printf("\n");
    	}
    	printf("\n");
    }
    
    void printO(double* O[30], double B[30], int m,int n)
    {
    	int i,j;
    
    	printf("current matrix:\n");
    	for(i=0;i<m;i++)
    	{
    		for(j=0;j<n;j++)
    			printf("%f ",O[i][j]);
    		printf("| %f",B[i]);
    		printf("\n");
    	}
    	printf("\n");
    }

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    4

    Question a run time error

    hi!

    i have a run time error, i tried to fix it but i failed....

    please help me if you figure it out.

    i think its about the scaling func.

    Code:
    #include <stdio.h>
    #include <math.h>
    
    void scaling(double* P[],double B[], int i,  int j,int order);
    
    void printA(double A[30][30], int m,int n);
    
    void printO(double* O[30], double B[30],int m,int n);
    
    void calc(double* O[30], double B[30], int m,int n,int order);
    
    int main()
    {
        double A[30][30];
        double B[30];
        double* O[30];
        int i,j,m,n,order;
    
    printf("enter the number of rows and columns: \n");
    scanf("%d%d",&i,&j);
    printf("enter %d*%d matrix\n:",i,j);
    
    for (m=0 ; m<i ; m++)
        for(n=0 ; n<j ; n++)
            scanf("%lf",&(A[m][n]));
    
    printf("enter %d vector: \n",i);
    
    for (m=0 ; m<i ; m++)
    scanf("%lf",&(B[m]));
     
    for(order=0;order<i;order++);
    {
    	scaling(O,B,i,j,order);
    	calc(O,B,i,j,order);
    	printA(A,i,j);
    	printO(O,B,i,j);
    }
    	return 0;
    }
    
    void scaling(double* P[],double B[], int i,  int j,int order)
    {
    int m,n,maxrow;
    double max[30], maxi=0,temp2;
    double* temp;
    	for(m=order;m<i;m++)
    		max[m]=0;
    
        for (m=order;m<i;m++)
            for(n=order;n<j;n++)
                          if (max[m]< fabs(P[m][n]))
     max[m]=fabs(P[m][n]);
    for (m=order;m<i;m++)
    	if ((fabs(P[m][order])/max[m])>maxi)
    		{
    		maxi=(fabs(P[m][order]/max[m]));
    		maxrow=m;
    		}
    if(maxrow!=order)
            {
                temp=P[maxrow];
                P[maxrow]=P[order];
                P[order]=temp;
    
                temp2=B[maxrow];
                B[maxrow]=B[order];
                B[order]=temp2;
    
            }
    
    }
    
    void printA(double A[30][30], int m,int n)
    {
    	int i,j;
    
    	printf("original coefficients matrix:\n");
    	for(i=0;i<m;i++)
    	{
    		for(j=0;j<n;j++)
    			printf("%.2lf ",A[i][j]);
    
    		printf("\n");
    	}
    	printf("\n");
    }
    
    void printO(double* O[30], double B[30], int m,int n)
    {
    	int i,j;
    
    	printf("current matrix:\n");
    	for(i=0;i<m;i++)
    	{
    		for(j=0;j<n;j++)
    			printf("%f ",O[i][j]);
    		printf("| %f",B[i]);
    		printf("\n");
    	}
    	printf("\n");
    }
    
    void calc(double* O[30], double B[30], int m,int n,int order)
    {
    	int i,j;
    
    for (i=order;i<m-1;i++);
    {
    		for (j=order;j<n;j++);
    		O[i+1][j]=O[i+1][j]-O[order][j]*O[order+1][order]/O[order][order];
    }
    }

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Calling variables "O" is a very BAD THING, because it makes them look so similar to the digit "0".

    When running your program with 2x2 matrix with the values 1, 2, 3, 4 and 1, 2 in the vector, it crashes with a NULL memory access here (at what seems to be O[1][1] ??):
    Code:
        O[i+1][j]=O[i+1][j]-O[order][j]*O[order+1][order]/O[order][order];
    I'm not entirely surprised at that, since O is an array of pointer, and you do not call malloc [or similar functions] in your code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Agreed.

    - Single letter identifiers.
    - poorly indented code.
    Neither are good when it comes to getting others to look at your code.
    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.

  7. #7
    Registered User
    Join Date
    May 2008
    Posts
    29
    hi,
    I'm doing this work with Miri.
    We fixed the 0-O mistake. It makes the run time error come a bit later...
    Anybody can figure out why it won't work?

    Thank you.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Livnat View Post
    hi,
    I'm doing this work with Miri.
    We fixed the 0-O mistake. It makes the run time error come a bit later...
    Anybody can figure out why it won't work?

    Thank you.
    Given that we have no idea what the new code looks like, how do you think we can know what is going wrong?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    May 2008
    Posts
    29
    I t looks pretty much the same. We changed the O's and the 0's to P's. Maybe we should change all the names to something more meaningful like you suggested . In the meantime, here's the code:

    Code:
    #include <stdio.h>
    #include <math.h>
    
    void scaling(double* P[],double B[], int i,  int j,int order);
    
    void printA(double A[30][30], int m,int n);
    
    void printP(double* P[30], double B[30],int m,int n);
    
    void calc(double* P[30], double B[30], int m,int n,int order);
    
    int main()
    {
       double A[30][30];
       double B[30];
       double* P[30];
       int i,j,m,n,order;
    
    printf("enter the number of rows and columns: \n");
    scanf("&#37;d%d",&i,&j);
    printf("enter %d*%d matrix\n:",i,j);
    
    for (m=0 ; m<i ; m++)
       for(n=0 ; n<j ; n++)
           scanf("%lf",&(A[m][n]));
    
    printf("enter %d vector: \n",i);
    
    for (m=0 ; m<i ; m++)
    scanf("%lf",&(B[m]));
    
    for(order=0;order<i;order++);
    {
           scaling(P,B,i,j,order);
           calc(P,B,i,j,order);
           printA(A,i,j);
           printP(P,B,i,j);
    }
           return 0;
    }
    
    void scaling(double* P[],double B[], int i,  int j,int order)
    {
    int m,n,maxrow;
    double max[30], maxi=0,temp2;
    double* temp;
           for(m=order;m<i;m++)
                   max[m]=0;
    
       for (m=order;m<i;m++)
           for(n=order;n<j;n++)
                         if (max[m]< fabs(P[m][n]))
     max[m]=fabs(P[m][n]);
    for (m=order;m<i;m++)
           if ((fabs(P[m][order])/max[m])>maxi)
                   {
                   maxi=(fabs(P[m][order]/max[m]));
                   maxrow=m;
                   }
    if(maxrow!=order)
           {
               temp=P[maxrow];
               P[maxrow]=P[order];
               P[order]=temp;
    
               temp2=B[maxrow];
               B[maxrow]=B[order];
               B[order]=temp2;
    
           }
    
    }
    
    void printA(double A[30][30], int m,int n)
    {
           int i,j;
    
           printf("original coefficients matrix:\n");
           for(i=0;i<m;i++)
           {
                   for(j=0;j<n;j++)
                           printf("%.2lf ",A[i][j]);
    
                   printf("\n");
           }
           printf("\n");
    }
    
    void printP(double* P[30], double B[30], int m,int n)
    {
           int i,j;
    
           printf("current matrix:\n");
           for(i=0;i<m;i++)
           {
                   for(j=0;j<n;j++)
                           printf("%f ",P[i][j]);
                   printf("| %f",B[i]);
                   printf("\n");
           }
           printf("\n");
    }
    
    void calc(double* P[30], double B[30], int m,int n,int order)
    {
           int i,j;
    
    for (i=order;i<m-1;i++);
    {
                   for (j=order;j<n;j++);
                   P[i+1][j]=(P[i+1][j]-P[order][j]*P[order+1][order]/P[order][order]);
    }
    }
    Thanks...

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So what is your P array pointing to? You only fixed the first of my two suggestions.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    Registered User
    Join Date
    Jul 2008
    Posts
    4

    problematic loop

    hi thank you!

    to simplify the problem, here is the problematic loop:

    Code:
    void diagonal(double* P[30], double B[30], int m,int n,int order)//diagonal b!!
    {
           int i,j,k;
    printf("im alive\n");
    for (i=order;i<m;i++)
                   for (j=0;j<order;j++)
    		for (k=1;k<m+1-order;k++)
                   P[i+k][j]=(P[i+k][j]-P[order][j]*P[order+k][order]/P[order][order]);
    printf("im alive\n");
    }


    and this is the intire code:
    Code:
    #include <stdio.h>
    #include <math.h>
    
    void scaling(double* P[],double B[], int i,  int j,int order);
    
    void printA(double A[30][30], int m,int n);
    
    void printP(double* P[30], double B[30],int m,int n);
    
    void diagonal(double* P[30], double B[30], int m,int n,int order);
    
    void calc(double* P[30], double B[30], int m,int n);
    
    int main()
    {
       double A[30][30];
       double B[30];
       double* P[30];
       int i,j,m,n,order;
    
    printf("enter the order of the matrix: \n");
    scanf("%d",&i);
    printf("enter %d*%d matrix:\n",i,i);
    j=i;
    for (m=0 ; m<i ; m++)
       for(n=0 ; n<j ; n++)
           scanf("%lf",&(A[m][n]));
    
    printf("enter %d vector: \n",i);
    
    for (m=0 ; m<i ; m++)
    scanf("%lf",&(B[m]));
    
    for (m=0;m<i;m++)
    		P[m]=A[m];
    printP(P, B, m, n);
    
    for(order=0;order<i;order++)
    {
           scaling(P,B,i,j,order);
    printA(A,i,j);
           printP(P,B,i,j);
           diagonal(P,B,i,j,order);
           printA(A,i,j);
           printP(P,B,i,j);
    }
    calc(P, B,  m, n);
           return 0;
    }
    
    void scaling(double* P[],double B[], int i,  int j,int order)
    {
    int m,n,maxrow;
    double max[30], maxi=0,temp2;
    double* temp;
           for(m=order;m<i;m++)
                   max[m]=0;
    
      for(m=order;m<i;m++)
                   printf("%f",max[m]);
    
       for (m=order;m<i;m++)
           for(n=order;n<j;n++)
                         if (max[m]< fabs(P[m][n]))
    {
     max[m]=fabs(P[m][n]);
    printf("max%d=%f\n",m,max[m]);
    }
    for (m=order;m<i;m++)
           if ((fabs(P[m][order])/max[m])>maxi)
                   {
                   maxi=(fabs(P[m][order]/max[m]));
                   maxrow=m;
                   }
    if(maxrow!=order)
           {
               temp=P[maxrow];
               P[maxrow]=P[order];
               P[order]=temp;
    
               temp2=B[maxrow];
               B[maxrow]=B[order];
               B[order]=temp2;
    
           }
    
    }
    
    void printA(double A[30][30], int m,int n)
    {
           int i,j;
    
           printf("original coefficients matrix:\n");
           for(i=0;i<m;i++)
           {
                   for(j=0;j<n;j++)
                           printf("%.2lf ",A[i][j]);
    
                   printf("\n");
           }
           printf("\n");
    }
    
    void printP(double* P[30], double B[30], int m,int n)
    {
           int i,j;
    
           printf("current matrix:\n");
           for(i=0;i<m;i++)
           {
                   for(j=0;j<n;j++)
                           printf("%f ",P[i][j]);
                   printf("| %f",B[i]);
                   printf("\n");
           }
           printf("\n");
    }
    
    void diagonal(double* P[30], double B[30], int m,int n,int order)//diagonal b!!
    {
           int i,j,k;
    printf("im alive\n");
    for (i=order;i<m;i++)
                   for (j=0;j<order;j++)
    		for (k=1;k<m+1-order;k++)
                   P[i+k][j]=(P[i+k][j]-P[order][j]*P[order+k][order]/P[order][order]);
    printf("im alive\n");
    }
    
    void calc(double* P[30], double B[30], int m,int n)
    {
    int i,j;
    double x[30],y[30];
    for (i=0;i<m;i++)
    y[i]=B[i];
    for (i=0;i<m;i++)
    x[i]=0;
    for (i=m;i>0;i--)
    {
    for (j=m;j>i;j--)
    y[i]-=P[i][j]*x[j];
    x[i]=y[i]/P[i][i];
    printf("x[%d]=%f",i,x[i]);
    }
    }
    we still have a run time error....

    thanks,
    miri & livnat

  12. #12
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    when i = m-1
    k = m-order
    i+k = 2m-order-1

    when order = 0 you are accessing index 2m-1 which could be way out of bounds

    I suppose other combinations of indexes are also bloated...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  13. #13
    Registered User
    Join Date
    May 2008
    Posts
    29
    thank you Vart.
    we did some adjestmants, here is the new loop...

    Code:
    void diagonal(double* P[30], double B[30], int m,int n,int order)//diagonal b!!
    {
           int j,k;
    printf("im alive\n");
    	for (k=1;k<m+1-order;k++)
           for (j=0;j<m;j++)
    	P[k+order][j+order]=(P[k+order][j+order]-P[order][j+order]*P[order+k][order]/P[order][order]);
    printf("im not alive\n");
    }

  14. #14
    Registered User
    Join Date
    May 2008
    Posts
    29

    we got it :)

    this is the fixed loop:

    Code:
    void diagonal(double* P[30],double B[30],int m,int order)//diagonal b!!
    {
           int j,k;
    	for (k=1;k<m-order;k++)
           for (j=0;j<m;j++)
    	P[k+order][j+order]=(P[k+order][j+order]-P[order][j+order]*P[order+k][order]/P[order][order]);
    
    }
    the hole code still doesn't work peoperly,,,
    we'll be back ....

  15. #15
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    j+order could be bigger than m
    in your inner loop - add the index checks with assert or printf
    Code:
    if(k+order <0 || k+order >= m) printf("k+order(&#37;d) error", k+order);
    if(j+order<0 || j+order>= m) printf("j+order(%d) error", j+order);
    if(order <0 || order >= m) printf("order(%d) error", order);
    for each index you are using...
    Last edited by vart; 07-24-2008 at 11:08 PM.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM