Thread: ****.exe stopped working (Second project i have)

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

    ****.exe stopped working (Second project i have)

    Ok. I have this program:

    Code:
    #include<stdlib.h>
    #include<stdio.h>
    #include<math.h>
    #include"mersenne.c"
    #define alpha 1.0734
    #define max_length 5000
    
    int i, j, l, n, m, max;
    void sortare(double *a,int n)
    {
    
        int i,schimb;
        float aux;
        do
        {
          schimb=0;
          for(i=0;i<n-1;i++)
              if(a[i]>a[i+1])
              {
                  aux=a[i];
                  a[i]=a[i+1];
                  a[i+1]=aux;
                  schimb=1;
               }
        }while(schimb);
    }
    int cauta(int i, int n, double *Y, int *cont, double val)
    {
        int mij;
        if(val<=Y[0]) 
           cont[0]++;
        else
        {
            if(i==(n-1))
               cont[n]++;
            else
            {
                 mij=(i+n)/2;
                 if(val<=Y[mij]) 
                    cauta(i,mij,Y,cont,val);
                 else 
                    cauta(mij,n,Y,cont,val);
            }
        }
    }
    int main()
    {
        FILE *f,*h,*g,*zdistr,*zsim;
        h=fopen("Zdateprel.txt","wt");
        f=fopen("Zdate1.txt","rt");
        g=fopen("Zprobteor.txt","wt");
        zdistr=fopen("Zdistr.txt","wt");
        zsim=fopen("Zdatesim.txt","wt");
        int *D,*viz;
        double sum=0,C,*pe,*Y,*sim,*prob,val;
        D=(int*)malloc(max_length*sizeof(int));
        if(!D)
        {
            printf("Eroare alocare memorie.\n");
            exit(EXIT_FAILURE);
        }
        i=0;
        while(!feof(f))
        {
             i++;
             fscanf(f,"%d",&D[i]);
             if(max<D[i])  max=D[i];
        }
        n=i;l=0;
        pe=(double*)malloc(n*sizeof(double));
        for(i=1;i<=max;i++)
        {
            int nr=0;
            for(j=1;j<=n;j++)
               if(i==D[j])   nr++;
            l++;     
            pe[l]=(double)nr/(double)n;
        }
        sortare(pe,l);
        for(i=1;i<=l;i++)
        {
             double k,y;
             k=log10(i+1);
             y=-log10(pe[i]);
             fprintf(h,"%lf %lf\n",k,y);
             fprintf(zdistr,"%lf\n",pe[i]);
        }
           for(i=1;i<=l;i++)
              sum=sum+1.0/pow(i,alpha);
        C=1/sum;
        Y=(double*)malloc(m*sizeof(double));
        for(i=1;i<=l;i++)
        {
            Y[i]=C/pow(i,alpha);
            fprintf(g,"%lf \n",Y[i]);
        }    
        sim=(double*)malloc(m*sizeof(double));
        for(i=1;i<=l;i++)
            sim[i]=genrand_real2();
        viz=(int*)malloc(l*sizeof(int));
        for(i=0;i<l;i++)
            viz[i]=0;
        for(i=0;i<=2000;i++)
        {
            val=sim[i];
            cauta(0,m,Y,viz,val);
        }
        prob=(double*)malloc(l*sizeof(double));
        for(i=1;i<=l;i++)
        {
            prob[i]=viz[i]/2000.0;
            fprintf(zsim,"%lf \n",prob[i]);
        }
        fclose(f);
        fclose(h);
        return 0;
    }
    Error given: Attachment 11957


    Input file is: Attachment 11958

    Mersenne: Attachment 11959

    Output is ZdatePrel,Zdatesim, Zdistr, Zprobteor.

    Someone?

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    You need to run your program from within your IDE (or maybe in the debugger) to get a programmer-level error message. This is some sort of braindead Windows user-level error message.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    In line 97 you allocate memory for "sim"
    Code:
    sim=(double*)malloc(m*sizeof(double));
    but m is never initialised.

    And your programming style is really awful (nondescriptive variable names, opening files without closing them, allocating memory without freeing, ...).

    Bye, Andreas
    Last edited by AndiPersti; 09-03-2012 at 12:57 PM. Reason: wrong answer

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Also, stop casting malloc and do not #include .c files.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program has stopped working...
    By asediugeneral in forum C Programming
    Replies: 4
    Last Post: 09-03-2012, 11:42 AM
  2. stopped working run time error.. help plz... ;(
    By fredsilvester93 in forum C Programming
    Replies: 10
    Last Post: 01-04-2012, 01:15 AM
  3. ****.exe has stopped working
    By kawaikx15 in forum C Programming
    Replies: 10
    Last Post: 11-19-2011, 07:38 AM
  4. .exe has stopped working
    By bluesky16 in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2011, 12:58 PM
  5. vshost.exe has stopped working
    By Marty21 in forum C# Programming
    Replies: 1
    Last Post: 06-08-2009, 10:41 AM