Thread: Codeblocks project.exe stopped working

  1. #1
    Registered User
    Join Date
    Jul 2014
    Posts
    13

    Codeblocks project.exe stopped working

    ive got no errors,no warning just stopped working any solution?


    Code:
    #include<stdio.h>
    #define N 10
    #define DEBUG 0
    #include<time.h>
    #include<stdlib.h>
    #include<math.h>
    
    
    
    
    
    
    int isSafe(int x,int y,int tomb[N][N],int megoldas[N][N])
    {
        if(x>=0 && x<N && y>=0 && y<N && tomb[x][y]==1 && !megoldas[x][y])
            return 1;
        else
            return 0;
    }
    int Keres(int tomb[N][N], int megoldas[N][N], int x,int y)
    {
        if(x==N-1)
        {
            megoldas[x][y]=1;
            return 1;
        }
        if(isSafe(x,y,tomb,megoldas)==1)
        {
            megoldas[x][y]=1;
            if(Keres(tomb,megoldas,x,y+1)==1)
                return 1;
            if(Keres(tomb,megoldas,x+1,y)==1)
                return 1;
            if(Keres(tomb,megoldas,x,y-1)==1)
                return 1;
            if(Keres(tomb,megoldas,x-1,y)==1)
                return 1;
            megoldas[x][y]=0;
        }
        return 0;
    }
    int main()
    {   int probalkozas=100,atment=0,ok=0,i,j,k,ism;
        float p=0.0;
        float reszatlag[20]={0};
        float atlag=0;
        float szoras=0;
    
    
        FILE * pFile;pFile=fopen("10x10.txt","a");
        srand(time(0));
    
    
        for(int v=0;v<10;v++) {
                p=p+0.1;
        for(int csinald=0;csinald<100;csinald++){
            atment=0;
        int tomb[N][N] = {{0}}; int megoldas[N][N] = {{0}};
        for(ism=0;ism<probalkozas;ism++)
        {
            for(i=0;i<N;i++)
            {
                for(j=0;j<N;j++)
                {
                    if(rand()%100+1 <= (p*100))
                        tomb[i][j]=1;
                    else
                        tomb[i][j]=0;
                }
            }
    
    
            ok=0;
            for(i=0;i<N;i++)
            {
                if(Keres(tomb,megoldas,0,i)==1 && ok==0)
                {
                    ok=1;
                    atment++;
    
    
                    for(j=0;j<N;j++)
                    {
                        for(k=0;k<N;k++)
                        {
    
    
                            megoldas[j][k]=0;
                        }
    
    
                    }
                }
            }
        }
        reszatlag[csinald]=(float)atment/(float)probalkozas;
    
    
        printf("P = %.2f\nTabla kitoltese: %dx\nSikeres ateresek szama: %d\nSikeres ateresek atlaga: %.4f \n ",p,probalkozas,atment,reszatlag[csinald]);
    
    
        }
        for(i=0;i<100;i++){atlag+=reszatlag[i];
        }
        atlag=atlag/100;
    
    
        for(i=0;i<110;i++) szoras=sqrt(((reszatlag[i]-atlag)*(reszatlag[i]-atlag))/20);
        fprintf(pFile,"%.3f %.4f %.4f\n",p*100,atlag*100,szoras*100);
        atlag=0;
        }
        return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    I may have mentioned this before, but your indentation needs work.
    https://en.wikipedia.org/wiki/Indent_style

    Code:
    #include<stdio.h>
    #define N 10
    #define DEBUG 0
    #include<time.h>
    #include<stdlib.h>
    #include<math.h>
    
    int isSafe(int x, int y, int tomb[N][N], int megoldas[N][N])
    {
      if (x >= 0 && x < N && y >= 0 && y < N && tomb[x][y] == 1 && !megoldas[x][y])
        return 1;
      else
        return 0;
    }
    
    int Keres(int tomb[N][N], int megoldas[N][N], int x, int y)
    {
      if (x == N - 1) {
        megoldas[x][y] = 1;
        return 1;
      }
      if (isSafe(x, y, tomb, megoldas) == 1) {
        megoldas[x][y] = 1;
        if (Keres(tomb, megoldas, x, y + 1) == 1)
          return 1;
        if (Keres(tomb, megoldas, x + 1, y) == 1)
          return 1;
        if (Keres(tomb, megoldas, x, y - 1) == 1)
          return 1;
        if (Keres(tomb, megoldas, x - 1, y) == 1)
          return 1;
        megoldas[x][y] = 0;
      }
      return 0;
    }
    
    int main()
    {
      int probalkozas = 100, atment = 0, ok = 0, i, j, k, ism;
      float p = 0.0;
      float reszatlag[20] = { 0 };
      float atlag = 0;
      float szoras = 0;
    
      FILE *pFile;
      pFile = fopen("10x10.txt", "a");
      srand(time(0));
    
      for (int v = 0; v < 10; v++) {
        p = p + 0.1;
        for (int csinald = 0; csinald < 100; csinald++) {
          atment = 0;
          int tomb[N][N] = { {0} };
          int megoldas[N][N] = { {0} };
          for (ism = 0; ism < probalkozas; ism++) {
            for (i = 0; i < N; i++) {
              for (j = 0; j < N; j++) {
                if (rand() % 100 + 1 <= (p * 100))
                  tomb[i][j] = 1;
                else
                  tomb[i][j] = 0;
              }
            }
    
            ok = 0;
            for (i = 0; i < N; i++) {
              if (Keres(tomb, megoldas, 0, i) == 1 && ok == 0) {
                ok = 1;
                atment++;
                for (j = 0; j < N; j++) {
                  for (k = 0; k < N; k++) {
                    megoldas[j][k] = 0;
                  }
                }
              }
            }
          }
          reszatlag[csinald] = (float) atment / (float) probalkozas;
    
          printf("P = %.2f\nTabla kitoltese: %dx\n"
                 "Sikeres ateresek szama: %d\n"
                 "Sikeres ateresek atlaga: %.4f \n ",
               p, probalkozas, atment, reszatlag[csinald]);
        }
    
        for (i = 0; i < 100; i++) {
          atlag += reszatlag[i];
        }
        atlag = atlag / 100;
    
        for (i = 0; i < 110; i++)
          szoras = sqrt(((reszatlag[i] - atlag) * (reszatlag[i] - atlag)) / 20);
    
        fprintf(pFile, "%.3f %.4f %.4f\n", p * 100, atlag * 100, szoras * 100);
        atlag = 0;
      }
      return 0;
    }
    > float reszatlag[20] = ...;
    You created a #define for N being 10, why not a #define for the other magic numbers in this code, like 20 and 100 ?

    Now the killer....
    Code:
    for (int csinald = 0; csinald < 100; csinald++)
    ...
    reszatlag[csinald] = (float) atment / (float) probalkozas;
    The key phrase here is "buffer overrun!!!"
    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.

  3. #3
    Registered User
    Join Date
    Jul 2014
    Posts
    13
    Thanks Trying to improve my indent style!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code.exe has stopped working
    By KJN in forum C++ Programming
    Replies: 1
    Last Post: 02-22-2014, 06:52 PM
  2. ****.exe stopped working (Second project i have)
    By asediugeneral in forum C Programming
    Replies: 3
    Last Post: 09-03-2012, 01:25 PM
  3. Program has stopped working...
    By asediugeneral in forum C Programming
    Replies: 4
    Last Post: 09-03-2012, 11:42 AM
  4. ****.exe has stopped working
    By kawaikx15 in forum C Programming
    Replies: 10
    Last Post: 11-19-2011, 07:38 AM
  5. .exe has stopped working
    By bluesky16 in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2011, 12:58 PM