Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
I fixed the next code
C#
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>

typedef struct _nodolista{
     int columnindex;
     struct _nodolista*next;
    int value;
}nodol;
typedef struct _nodocabecera{
    int rowindex;
    nodol * next;
    struct _nodocabecera*down;
}nodoc;
typedef struct _matrix{
      nodoc*idlist;/* id   list*/
      nodol*valuelist;/*value row list*/
    }matrix;
/*this function initializes the IDlist*/
    nodoc * iniID(int m){
        nodoc* IDlist;
        int i;
        IDlist=( nodoc*)malloc(m*sizeof( nodoc));

         /*now we create the list of identifiers*/
        for (i=1;i<=m;i++){
            if (i==m){
                        IDlist->rowindex=m;
                        IDlist->next=NULL;
                        IDlist->down=NULL;
            return IDlist;
                        }
            IDlist->rowindex=i;
            IDlist->next=NULL;
            IDlist=IDlist->down;
        }
    return IDlist;
}
matrix * iniM(int m , int n){
    matrix * x;
    int i=1;
    /*we create the disperse matrix*/
            x=(matrix *)malloc(m*n*sizeof(matrix));
            /*we create the idlist*/
            x->idlist=iniID(m);
            /*we create the value list*/
            nodol* valuelist;
            nodoc * aux;
            x->valuelist=NULL;
                for(aux=x->idlist;aux->down!=NULL;aux=aux->down){
                    valuelist=(nodol*)malloc(sizeof(nodol));
                    aux->next=valuelist;
                    valuelist->columnindex=i;
                    for (i=2;i<=n;i++){
                        if (i==n){
                        valuelist=(nodol*)malloc(sizeof(nodol));
                        valuelist->columnindex=n;
                        valuelist->value=0;
                        valuelist->next=NULL;
                        return x ;
                        }
                        valuelist=(nodol*)malloc(sizeof(nodol));
                        valuelist->columnindex=i;
                        valuelist->value=0;
                        valuelist=valuelist->next;
                        } return x;
                }
                return x;
}


int dpmatrix(matrix *x){
        int i,j,val;
        nodoc * aux;
        nodol * aux2;

    for (aux=x->idlist;aux->down!=NULL;aux=aux->down){
            i=aux->rowindex;
            aux->next=x->valuelist;

        for (aux2=aux->next;aux2->next!=NULL;aux2=aux2->next){
                   j=aux2->columnindex;
                    printf("%d,%d introduzca elemento",i,j);
                    scanf("%d",&val);
                    if (val!=0 )
                    aux2->value=val;
                }
        }
return 0;
}


 int main(){
    int i,j;
    matrix * M;
    printf("introduzca el numero de filas \n");
    scanf("%d",&i);
    printf("introduzca el numero de columnas \n");
    scanf("%d",&j);
    M=iniM(i,j);
    dpmatrix(M);
return 0;
 }




, but it's still not compiling yet, when i run the program, it takes the numbers of rows and columns, then the program hangs, and i don't if it's a problem of assignment of memory, cuz' the code doesn't show any errors and the logic of the algorithm is well, please somebody help me with this problem ! ;( thanks in advance
Posted
Updated 25-Jan-11 3:59am
v4
Comments
Christian Graus 24-Jan-11 19:26pm    
So, you 'got the code' and it 'doesn't compile'. Is this a quiz ? Do you tink the harder you make it for us, the more likely we are to help ? What doesn't compile ? Where is the problem ? What is the error message ? What have you done in response to what the message is telling you ?
Indivara 24-Jan-11 23:04pm    
Fixed HTML, update as Christian says above...

There are probably several things wrong, without proper formatting and so forth I haven't got the energy to read it - particularly since you don't tell use what the compiler is complaining about. However this leapt out as a possible reason for non-compilation:
C#
void initializeMatrix(matrix** M, long m,long n) {

C#
matrix ** h;

C#
initializeMatrix(*h,filas,columnas);

Try removing the "*" from the "*h" so the parameters match what you are passing...
 
Share this answer
 
The code is buggy, i.e. it has a lot of errors (for instance nodoc has not either next nor value member).
You have to:

1. Read carefully the compiler error messages.
2. Try yourself to fix the errors, asking here specific questions whenever you're stuck.


Good luck.
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900