Thread: Program has stopped working...

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    4

    Angry Program has stopped working...

    I can't figure out why... Can you help a bit?

    Here are the auxiliar files: Attachment 11954

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    #include "mersenne.c"
    #define alpha 0.85
    #define NN 1000
    
    int nr=0;
    void sortare(double *v1, int *v2, int lun){
      int i, modif, aux;
      double aux2;
     do{
      modif=0;
      for(i=1;i<lun;++i)
       if(v1[i-1] < v1[i]) {
        aux2=v1[i-1];
        v1[i-1]=v1[i];
        v1[i]=aux2;
        aux=v2[i-1];
        v2[i-1]=v2[i];
        v2[i]=aux;
        modif=1; }
     }while(modif);
    };
    /*
    double *prodLinieMatrice(int m, double *pi, double **G)
    {
       int i,j;
       double p;
       p=0;
       for(i=0;i<m;i++)
       {
          for(j=1;j<m;j++)
              p=p+pi[i]*G[i][j];   
       }  
       return p;    
    }*/
    double norma(int m, double *v)
    {
        int i;
        double sum=0;
        for(i=0;i<m;i++)
           sum=sum+v[i]*v[i];
        return sqrt(sum);
    }
    double *diferentaV(int m, double *v, double *w)
    {
           int i;
           double *dif;
           if((dif=(double*)malloc(m*sizeof(double*)))==NULL)
           {
             printf("Eroare la alocare dinamica");
             exit(1);
           }
           for(i=0;i<m;i++)
           dif[i]=v[i]-w[i];
           return dif;
    }
    int *simDistr(double *pi,double **g,int n,int m)
    {
           double u,F,*p;
           int j,k,i,*s;
           if((s=(int*)malloc(n*sizeof(int)))==NULL)
           {
             printf("Eroare la alocare dinamica");
             exit(1);
           }
           if((p=(double*)malloc(m*sizeof(double)))==NULL)
           {
             printf("Eroare la alocare dinamica");
             exit(1);
           }
           j=0;
           u=genrand_real2();
           F=pi[0];
           while(u>F)
           {
              j=j+1;
              F=F+pi[j];
           }
           s[0]=j;
           i=s[0];
           for(k=0;k<n;k++)
           {
               p=g[i];
               j=0;
               u=genrand_real2();
               F=p[0];
               while(u>F)
               {
                  j=j+1;
                  F=F+p[j];
               }
               s[k]=j;
               i=s[k];
            }
            return s;
    }
    
    int main(void)
    {
        FILE *f,*k;
        int m=13;
          int i,j,z,*lm,**H;
          double **Q,**G,**e;
        f=fopen("hyperlink.in","rt");
        if(!f)
        {
             printf("eroare la fisier");
             exit(1);
        }
        if((H=(int**)malloc(m*sizeof(int*)))==NULL)
           {
             printf("Eroare la alocare dinamica");
             exit(1);
           }
        for(i=0;i<m;i++)
            H[i]=(int*)malloc(m*sizeof(int));
        for(i=0;i<m;i++)
          for(j=0;j<m;j++)
              fscanf(f,"%d",&H[i][j]); 
        if((Q=(double**)malloc(m*sizeof(double*)))==NULL)
           {
             printf("Eroare la alocare dinamica");
             exit(1);
           }
        for(i=0;i<m;i++)
            Q[i]=(double*)malloc(m*sizeof(double));
         for(i=0;i<m;i++)
          for(j=0;j<=m;j++)
             Q[i][j]=0;
       
        for(i=0;i<m;i++)
        {
           int k=0;         
           for(j=0;j<m;j++)
              if(H[i][j]!=0) k++;
           if(k!=0)  
           {   
              for(j=0;j<m;j++)
                  if(H[i][j]==1) Q[i][j]=1.0/k;               
           }
           else
           if(k==0)
              for(z=0;z<m;z++)
                  Q[i][z]=1.0/m;
        }   
        if((G=(double**)malloc(m*sizeof(double*)))==NULL)
           {
             printf("Eroare la alocare dinamica");
             exit(1);
           }
        for(i=0;i<m;i++)
            G[i]=(double*)malloc(m*sizeof(double));
        printf("\n aici \n");
        if((e=(double**)malloc(m*sizeof(double*)))==NULL)
           {
             printf("Eroare la alocare dinamica");
             exit(1);
           }         
        
        for(i=0;i<m;i++)
            e[i]=(double*)malloc(m*sizeof(double));
        for(i=0;i<m;i++)
           for(j=0;j<m;j++)  e[i][j]=1.0/m;
        
        for(i=0;i<m;i++)
           for(j=0;j<m;j++)
              G[i][j]=alpha*Q[i][j]+(1-alpha)*e[i][j];
        for(i=0;i<m;i++)
           for(j=0;j<m;j++)
              printf("%.3lf ",G[i][j]); 
        fclose(f);
        fclose(k);
        system("pause");
        return 0;
    }
    Last edited by asediugeneral; 09-03-2012 at 11:00 AM.

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by asediugeneral View Post
    I can't figure out why... Can you help a bit?
    "Program has stopped working" is a pretty useless problem description.
    What errors do you get? What are your inputs? What is the expected output? What is the problematic output?

    Read also How To Ask Questions The Smart Way

    Bye, Andreas

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    4
    THe input is hyperlink.txt (forgot to put it, my fault), output should the the G matrix.

    P1.cpp (forget about it, it's something that i did to help myself).
    mersenne.c helps me to do the page-ranking.


    No errors are generated, it start to compile and i get that error that ****.exe is stopped working"

    Sorry for inappropriate style of making the topic.


    Attachment 11956 (i changed the extension in *.txt for upload , it supposed to be *.in)

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Please copy&paste the exact error message, don't retype it. (You should really read the link I've posted).

    Problem 1: On line 130 you have a buffer overflow
    Code:
    for(j=0;j<=m;j++)
    j will be 13 in the last iteration, which is an invalid index for your arrays.

    Problem 2: You are closing a file (k) in line 174 which you haven't opened.

    Bye, Andreas

  5. #5
    Registered User
    Join Date
    Sep 2012
    Posts
    4
    Thanks a lot! that was the problem. I figured out from there. You have a bright future!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ****.exe has stopped working
    By kawaikx15 in forum C Programming
    Replies: 10
    Last Post: 11-19-2011, 07:38 AM
  2. .exe has stopped working
    By bluesky16 in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2011, 12:58 PM
  3. vshost.exe has stopped working
    By Marty21 in forum C# Programming
    Replies: 1
    Last Post: 06-08-2009, 10:41 AM
  4. Replies: 4
    Last Post: 03-26-2008, 08:48 AM
  5. Mouse scroll stopped working
    By Waldo2k2 in forum Tech Board
    Replies: 2
    Last Post: 10-12-2004, 11:25 AM