help with compiled program

This is a discussion on help with compiled program within the C Programming forums, part of the General Programming Boards category; Ive just downloaded Dev c++ and used it to compille my program. I then tried to run it. When it ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    16

    help with compiled program

    Ive just downloaded Dev c++ and used it to compille my program. I then tried to run it. When it got to the second part it stopped running and windows had to shut it down. Can anyone help me with this?

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    102
    There will be some bugs in your program. Check it out.
    You have also not mentioned whether you are able to operate system or not. If you can operate goto task manager->process and remove the exe file running over there.
    Saravanan.T.S.
    Beginner.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    16
    Here is the program, could you please tell me what bugs? It compiled fine...

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
    
    char buf[100000];
    unsigned int  lenf;
    int buff[20];
    float x[100000];
    float y[100000];
    float z[100000];
    float ca[20000];
    int main ()
    {
    char c = 'c';
    char a = 'a';
    char s = ' ';
    FILE *ifp;
    FILE *ifpp;
    
    
    int i;
    int r;
    int n;
    int num;
    
    float newr;
    float fd;
    float split;
    int spli;
    char fileo;
    printf ("What is the file you wish to open? \n");
    scanf ("%c", &fileo);
    printf ("Enter the amount of subspaces, 2,4 or 8. \n");
    scanf ("%f", &split);
    printf ("Confirm the amount of subspaces, 2,4 or 8.");
    scanf ("%i", &spli); 
    /*Using test file, user input to be added later*/
    /* Now that all variables are declared, open the file, get its size, and store it to a buffer. */
    ifp = fopen("fileo", "rt");
    fseek(ifp, 0L, SEEK_END);     /* Position to end of file */
    lenf = ftell(ifp);        /* Get file length */
    rewind(ifp);
    fread(buf, lenf, 1, ifp);
    for (i=0; i<lenf; i++)
     {  if (buf[i] == c)
         {  if (buf[i+1] == a)
           {    if (buf[i+2] == s)
             {     if (buf[i+3] == s)
               {      buf[i+18] = buff[0];
                      buf[i+19] = buff[1];
                      
                      buf[i+21] = buff[3];
                      buf[i+22] = buff[4];
                      buf[i+23] = buff[5];
                      x[r] = buff[0] * 10 + buff[1] + buff[3] * .1 + buff[4] * .01 + buff[5] * .001;  /* get x position of each ca */
                      buf[i+26] = buff[0];
                      buf[i+27] = buff[1];
                      
                      buf[i+29] = buff[3];
                      buf[i+30] = buff[4];
                      buf[i+31] = buff[5];
                      y[r] = buff[0] * 10 + buff[1] + buff[3] * .1 + buff[4] * .01 + buff[5] * .001;  /* get y position of each ca */
    
                      buf[i+26] = buff[0];
                      buf[i+27] = buff[1];
                      
                      buf[i+29] = buff[3];
                      buf[i+30] = buff[4];
                      buf[i+31] = buff[5];
                      z[r] = buff[0] * 10 + buff[1] + buff[3] * .1 + buff[4] * .01 + buff[5] * .001; /* get z position of each ca */
                      r++; /*Update info for next ca */
                      
                            }}}}}
    Compute: 
    for (n=0; n<=r; n++)
       { if (spli = 2)
    {if (z[n] < 0.00)
           ca[num]=z[n]; 
           {n++; }}
        if (spli = 4)
       { if (y[n] < 5.00 && z[n] < 0.00)
           { ca[num]=z[n];  
             num++;
             }    }
     if (spli = 8)
       { if (y[n] < 5.00 && z[n] < 0.00 && x[n] < 5.00)
           { ca[num]=y[n];  num++;
             }    }  }      
    newr = log10(num) / log10(r);
    fd = split / newr;
    fclose (ifp);
    printf("The fractal dimension is %f", fd );
    getch();
    }

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    102
    I think you might have reached above data segment memory area. So it hangs. avoid using such huge figures to declared as global.
    please use tags.
    Saravanan.T.S.
    Beginner.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    16
    So you say to declare them in main?

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    16
    I lowered the figures despite the fact they need to be pretty high. And it still doesnt work. Can you help me?

  7. #7
    Registered User
    Join Date
    Jul 2003
    Posts
    102
    Can you brief me about your program so that i could get logic quickly from your code.
    Saravanan.T.S.
    Beginner.

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    16
    The code is suppposed to take information from a text file of a format called a .pdb. Then it reads it to an array (buf) and then searches for certain information. Then it filters this information based on user input at the beginning. It is the user that also decides what file is to be opened.

  9. #9
    Registered User
    Join Date
    Aug 2003
    Posts
    16
    it says segmentation access violation? What does that mean?

  10. #10
    Registered User
    Join Date
    Aug 2003
    Posts
    16
    it doesnt even get up to lenf though, it fails atthe gathering of split and spli

  11. #11
    Registered User
    Join Date
    Aug 2003
    Posts
    16
    It still crashes.

    The output before it crshes is

    What is the file you wish to open?
    Enter the amount of Subspaces. Confirm the amount of subspaces

    Then it crashes. It does not activate the first scanf in front of amount and confirm.

  12. #12
    Registered User
    Join Date
    Aug 2003
    Posts
    16
    it still says An Access Violation (Segmentation Fault) occured in your program.

  13. #13
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Add some print statements to check values, specifically lenf, as well as split and spli after each is assigned a value.

    Also, you didn't test that the fopen(), fread(), and fseek() worked. Test for errors
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  14. #14
    Registered User
    Join Date
    Aug 2003
    Posts
    16
    It doesnt get to the part where any values are assigned. IT just gets passed the first 2 printfs!

  15. #15
    Registered User
    Join Date
    Jul 2003
    Posts
    102
    Are you able to execute "Hello World" program??. If it works then try to reduce the array size as it would dump data area. Everything you declare as global will get stored in data area of memory. So better avoid using such large arrays as global.
    Saravanan.T.S.
    Beginner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21