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?
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?
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.
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(); }
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.
So you say to declare them in main?
I lowered the figures despite the fact they need to be pretty high. And it still doesnt work. Can you help me?
Can you brief me about your program so that i could get logic quickly from your code.
Saravanan.T.S.
Beginner.
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.
it says segmentation access violation? What does that mean?
it doesnt even get up to lenf though, it fails atthe gathering of split and spli
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.
it still says An Access Violation (Segmentation Fault) occured in your program.
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
It doesnt get to the part where any values are assigned. IT just gets passed the first 2 printfs!
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.