access violation(segmentational fault) gah

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jun 2008
Posts: 3
Reputation: Vao is an unknown quantity at this point 
Solved Threads: 0
Vao Vao is offline Offline
Newbie Poster

access violation(segmentational fault) gah

 
0
  #1
Jun 27th, 2008
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void showBoard(int pLife[],int pType[]) {// WORKS NO-TOUCHY!
  5. int i;
  6.  
  7. printf("\n*-----------------------------------*\n");
  8. printf("| | | | | | |\n");
  9. for(i=0;i<=5;i++) {printf("| %d-%d ",pLife[i],pType[i]);} printf("|\n");
  10. printf("| | | | | | |\n");
  11. printf("|-----+-----+-----+-----+-----+-----|\n");
  12. printf("| | | | | | |\n");
  13. for(i=6;i<=11;i++) {printf("| %d-%d ",pLife[i],pType[i]);} printf("|\n");
  14. printf("| | | | | | |\n");
  15. printf("|-----+-----+-----+-----+-----+-----|\n");
  16. printf("| | | | | | |\n");
  17. for(i=12;i<=17;i++) {printf("| %d-%d ",pLife[i],pType[i]);} printf("|\n");
  18. printf("| | | | | | |\n");
  19. printf("|-----+-----+-----+-----+-----+-----|\n");
  20. printf("| | | | | | |\n");
  21. for(i=18;i<=23;i++) {printf("| %d-%d ",pLife[i],pType[i]);} printf("|\n");
  22. printf("| | | | | | |\n");
  23. printf("|-----+-----+-----+-----+-----+-----|\n");
  24. printf("| | | | | | |\n");
  25. for(i=24;i<=29;i++) {printf("| %d-%d ",pLife[i],pType[i]);} printf("|\n");
  26. printf("| | | | | | |\n");
  27. printf("|-----+-----+-----+-----+-----+-----|\n");
  28. printf("| | | | | | |\n");
  29. for(i=30;i<=35;i++) {printf("| %d-%d ",pLife[i],pType[i]);} printf("|\n");
  30. printf("| | | | | | |\n");
  31. printf("*-----------------------------------*\n\n");
  32. }
  33. void manualEntry(int pLife[],int pType[],int pPos,int wantedLife,int wantedType) {// WORKS NO-TOUCHY!
  34. pLife[pPos]=wantedLife;
  35. pType[pPos]=wantedType;
  36. }
  37. void resetBoardLife(int pLife[],int wantedLife) {// WORKS NO-TOUCHY!
  38. short i;
  39.  
  40. for(i=0;i<=35;i++) {
  41. pLife[i]=wantedLife;
  42. }
  43. }
  44. void resetBoardType(int pType[],int wantedType) {// WORKS NO-TOUCHY!
  45. short i;
  46.  
  47. for(i=0;i<=35;i++) {
  48. pType[i]=wantedType;
  49. }
  50. }
  51. int getPieceCount(int pLife[]) {// WORKS NO-TOUCHY!
  52. int i;
  53. int pieceCount=0;
  54.  
  55. for(i=0;i<=35;i++) {
  56. if(pLife[i]!=0) {
  57. pieceCount+=1;
  58. }
  59. }
  60. return pieceCount;
  61. }
  62. void boardPOut(int pType[],int pLife[],int pOut[36][36],int pOutLength[]) { //WORKS NO TOUCHY
  63. int i;
  64.  
  65. for(i=0;i<36;i++) {
  66. if(pLife[i]>0) {
  67. moveList(pType[i],i,pOut,pOutLength);
  68. }
  69. }
  70. }
  71. void showPOut(int pPos,int pOut[36][36],int pOutLength[]) { //WORKS NO TOUCHY
  72. int i;
  73.  
  74. for(i=0;i<pOutLength[pPos];i++) {
  75. printf("%d:%d ",i,pOut[pPos][i]);
  76. }
  77. }
  78. void setStartingPosition(int startingPosition[],int *startingPositionAmount) {// Testime
  79. int i=0;
  80. int exitArray=1;
  81. int enteredValue1;
  82.  
  83. printf("%d: ",i+1);
  84. scanf("%d",&enteredValue1);
  85. startingPosition[i]=enteredValue1;
  86. do {
  87. printf("Add more?(YES=1 NO=0)");
  88. scanf("%d",&exitArray);
  89.  
  90. i+=1;
  91. if(exitArray==1) {
  92. printf("%d: ",i+1);
  93. scanf("%d",&enteredValue1);
  94. startingPosition[i]=enteredValue1;
  95. } else {
  96. *startingPositionAmount=i;
  97. }
  98. } while(exitArray==1);
  99. printf("\n");
  100. }
  101. void testStartPos(int startingPosition[],int startingPositionAmount) {// Testime
  102. int i;
  103.  
  104. for(i=0;i<startingPositionAmount;i++) {
  105. printf("%d:%d ",i,startingPosition[i]);
  106. }
  107. printf("\n");
  108.  
  109. }
  110. void solver1(int pLife[],int pOut[36][36],int pOutLength[],int startingPosition[],int startingPositionAmount,int bestPath[36],int *bestPathLength) { // incomplete of course
  111. int i,x,a,b,c,d,e;
  112. int currentPos;int currentPath[36];
  113. int dummyPLife[36];
  114. int hasDecreased=0;
  115.  
  116. for(e=0;e<36;dummyPLife[e]=pLife[e],e++);
  117. *bestPathLength=0;
  118.  
  119. for(i=0;i<startingPositionAmount;i++){
  120. if(dummyPLife[startingPosition[i]]>0) {
  121. currentPath[currentPos]=startingPosition[i];
  122. dummyPLife[startingPosition[i]]-=1;
  123.  
  124. currentPos+=1;
  125. for(x=0;x<999;x++) { // 999 is a devil standing on its head so i had to pick it :D
  126. if(currentPos==0){ //exit this loop if currentPos is at 0
  127. break;
  128. }
  129. if(x<pOutLength[currentPath[currentPos-1]]) {
  130. if(dummyPLife[pOut[currentPath[currentPos-1]][x]]>0) { //go up 1 level
  131. currentPath[currentPos]=pOut[currentPath[currentPos-1]][x];
  132. dummyPLife[currentPath[currentPos]]-=1; //reduce 1 dummyPLife
  133.  
  134. currentPos+=1; //new currentPos
  135. x=0; //reseted to 0 for loop
  136. }
  137. } else { // go down 1 level
  138. if(currentPos>*bestPathLength) { //update bestPathLength and bestPath (if its better)
  139. *bestPathLength=currentPos;
  140. for(a=0;a<*bestPathLength;a++) {
  141. bestPath[a]=currentPath[a];
  142. }
  143. }
  144. currentPos-=1; //currentPos lower by 1
  145. dummyPLife[currentPath[currentPos]]+=1; //put back latest dummyPLife
  146. for(c=0;c<pOutLength[currentPath[currentPos]];c++) {
  147. if(currentPath[currentPos]==pOut[currentPath[currentPos]][c]) {
  148. x=c;
  149. break;
  150. }
  151. }
  152. }
  153. }
  154. }
  155. }
  156. printf("\n");
  157. printf("bestPathLength = %d\n",*bestPathLength);
  158. printf("%d",bestPath[0]);
  159. for(d=1;d<*bestPathLength;d++) {
  160. printf("-%d",bestPath[d]);
  161. }
  162. }
  163. void testMoveList(int pType,int pPosition,int pOut[][],int pOutLength[]) {
  164. switch(pType) {
  165. case 0:
  166. switch(pPosition) {
  167. case 0:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  168. case 1:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  169. case 2:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  170. case 3:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  171. case 4:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  172. case 5:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  173. default:printf("too far >:D");
  174. }
  175. case 1:
  176. switch(pPosition) {
  177. case 0:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  178. case 1:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  179. case 2:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  180. case 3:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  181. case 4:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  182. case 5:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  183. default:printf("too far >:D");
  184. }
  185. case 2:
  186. switch(pPosition) {
  187. case 0:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  188. case 1:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  189. case 2:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  190. case 3:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  191. case 4:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  192. case 5:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  193. default:printf("too far >:D");
  194. }
  195. case 3:
  196. switch(pPosition) {
  197. case 0:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  198. case 1:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  199. case 2:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  200. case 3:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  201. case 4:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  202. case 5:printf("pType=%d, pPosition=%d",pType,pPosition);return;
  203. default:printf("too far >:D");
  204. }
  205. default:printf("too far >:D");
  206. }
  207.  
  208. }
  209.  
  210.  
  211. int main(int argc,char *argv[]) {
  212. int quit=0;
  213. int pLife[36];
  214. int pType[36];
  215. int startingPosition[36];
  216. int startingPositionAmount=0;
  217. int pOut[36][36];
  218. int pOutLength[36];
  219. int i;
  220. int bestPath[36];
  221. int bestPathLength;
  222.  
  223. printf("Welcome...\n");
  224. resetBoardLife(pLife,0);
  225. resetBoardType(pType,0);
  226. showBoard(pLife,pType);
  227. do {
  228. int enteredCommand;
  229. int enteredValue1;
  230. int enteredValue2;
  231. int enteredValue3;
  232.  
  233. printf("+----(1)----+-----(2)-----+-----(3)------+-----(4)------+-----(5)-----+\n");
  234. printf("|manualEntry| setStartPos |resetBoardLife|resetBoardType| solver1 |\n");
  235. printf("+====(6)====+=====(7)=====+=====(8)======+=====(9)======+=====(10)====+\n");
  236. printf("| | boardPOut | showPOut | moveList | |\n");
  237. printf("+----(11)---+-----(12)----+-----(13)-----+-----(14)-----+-----(15)----+\n");
  238. printf("| |getPieceCount| testStartPos | testMoveList | quit |\n");
  239. printf("+-----------+-------------+--------------+--------------+-------------+\n");
  240. scanf("%d",&enteredCommand);
  241. switch (enteredCommand) {
  242. case 1:printf("Location:");
  243. scanf("%d",&enteredValue1);
  244. printf(" pLife:");
  245. scanf("%d",&enteredValue2);
  246. printf(" pType:");
  247. scanf("%d",&enteredValue3);
  248. manualEntry(pLife,pType,enteredValue1,enteredValue2,enteredValue3);
  249. break;
  250. case 2:setStartingPosition(startingPosition,&startingPositionAmount);
  251. break;
  252. case 3:printf(" pLife:");
  253. scanf("%d",&enteredValue1);
  254. resetBoardLife(pLife,enteredValue1);
  255. break;
  256. case 4:printf(" pType:");
  257. scanf("%d",&enteredValue1);
  258. resetBoardType(pType,enteredValue1);
  259. break;
  260. case 5:solver1(pLife,pOut,pOutLength,startingPosition,startingPositionAmount,bestPath,&bestPathLength);
  261. break;
  262. case 7:
  263. boardPOut(pType,pLife,pOut,pOutLength);
  264. break;
  265. case 8:printf("pPosition to printf array:");
  266. scanf("%d",&enteredValue1);
  267. showPOut(enteredValue1,pOut,pOutLength);
  268. break;
  269. case 9:printf("pType(0-8):");
  270. scanf("%d",&enteredValue1);
  271. printf("pPosition(0-35):");
  272. scanf("%d",&enteredValue2);
  273. moveList(enteredValue1,enteredValue2,pOut,pOutLength);
  274. break;
  275. case 12:printf("There is %d pieces left.",getPieceCount(pLife));
  276. break;
  277. case 13:testStartPos(startingPosition,startingPositionAmount);
  278. break;
  279. case 14:printf("pType(0-8):");
  280. scanf("%d",&enteredValue1);
  281. printf("pPosition(0-5):");
  282. scanf("%d",&enteredValue2);
  283. testMoveList(enteredValue1,enteredValue2,pOut,pOutLength);
  284. break;
  285. case 15:quit=1;
  286. break;
  287. default:printf("error\n\n");
  288. }
  289. showBoard(pLife,pType);
  290. } while(quit==0);
  291. return 0;
  292. }
I removed function moveList.. and uploaded it here. http://s219376922.onlinehome.us/misc/moveList.txt
Ok heres the code, now heres where the problem is..
  1. void solver1(int pLife[],int pOut[36][36],int pOutLength[],int startingPosition[],int startingPositionAmount,int bestPath[36],int *bestPathLength) { // incomplete of course
  2. int i,x,a,b,c,d,e;
  3. int currentPos;int currentPath[36];
  4. int dummyPLife[36];
  5. int hasDecreased=0;
  6.  
  7. for(e=0;e<36;dummyPLife[e]=pLife[e],e++);
  8. *bestPathLength=0;
  9.  
  10. for(i=0;i<startingPositionAmount;i++){
  11. if(dummyPLife[startingPosition[i]]>0) {
  12. currentPath[currentPos]=startingPosition[i];
  13. dummyPLife[startingPosition[i]]-=1;
  14.  
  15. currentPos+=1;
  16. for(x=0;x<999;x++) { // 999 is a devil standing on its head so i had to pick it :D
  17. if(currentPos==0){ //exit this loop if currentPos is at 0
  18. break;
  19. }
  20. if(x<pOutLength[currentPath[currentPos-1]]) {
  21. if(dummyPLife[pOut[currentPath[currentPos-1]][x]]>0) { //go up 1 level
  22. currentPath[currentPos]=pOut[currentPath[currentPos-1]][x];
  23. dummyPLife[currentPath[currentPos]]-=1; //reduce 1 dummyPLife
  24.  
  25. currentPos+=1; //new currentPos
  26. x=0; //reseted to 0 for loop
  27. }
  28. } else { // go down 1 level
  29. if(currentPos>*bestPathLength) { //update bestPathLength and bestPath (if its better)
  30. *bestPathLength=currentPos;
  31. for(a=0;a<*bestPathLength;a++) {
  32. bestPath[a]=currentPath[a];
  33. }
  34. }
  35. currentPos-=1; //currentPos lower by 1
  36. dummyPLife[currentPath[currentPos]]+=1; //put back latest dummyPLife
  37. for(c=0;c<pOutLength[currentPath[currentPos]];c++) {
  38. if(currentPath[currentPos]==pOut[currentPath[currentPos]][c]) {
  39. x=c;
  40. break;
  41. }
  42. }
  43. }
  44. }
  45. }
  46. }
  47. printf("\n");
  48. printf("bestPathLength = %d\n",*bestPathLength);
  49. printf("%d",bestPath[0]);
  50. for(d=1;d<*bestPathLength;d++) {
  51. printf("-%d",bestPath[d]);
  52. }
  53. }

The error is: An access violation(segmentational fault) on line 20 of this block down here.

This program checks a grid of 6x6, each square has a life(0~2) and a piece type(1,2,3,4,horse,bishop,tower,queen,and teleport to any other piece). The goal of this is to hit the most pieces possible...

Im pretty new to programming, so this error must come from pointers.. or bad logistic. :[
Please guide me on what it could be. Thanks

Any tips welcome! Even if it doesnt solve this. =D
Last edited by Vao; Jun 27th, 2008 at 1:20 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: access violation(segmentational fault) gah

 
0
  #2
Jun 27th, 2008
Any tips welcome! Even if it doesnt solve this. =D
Codes along with relevant comments always get more help!
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.

"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 3
Reputation: Vao is an unknown quantity at this point 
Solved Threads: 0
Vao Vao is offline Offline
Newbie Poster

Re: access violation(segmentational fault) gah

 
0
  #3
Jun 27th, 2008
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void showBoard(int pLife[],int pType[]) { //Simply printf the whole board
  5. int i;
  6.  
  7. printf("\n*-----------------------------------*\n");
  8. printf("| | | | | | |\n");
  9. for(i=0;i<=5;i++) {printf("| %d-%d ",pLife[i],pType[i]);} printf("|\n");
  10. printf("| | | | | | |\n");
  11. printf("|-----+-----+-----+-----+-----+-----|\n");
  12. printf("| | | | | | |\n");
  13. for(i=6;i<=11;i++) {printf("| %d-%d ",pLife[i],pType[i]);} printf("|\n");
  14. printf("| | | | | | |\n");
  15. printf("|-----+-----+-----+-----+-----+-----|\n");
  16. printf("| | | | | | |\n");
  17. for(i=12;i<=17;i++) {printf("| %d-%d ",pLife[i],pType[i]);} printf("|\n");
  18. printf("| | | | | | |\n");
  19. printf("|-----+-----+-----+-----+-----+-----|\n");
  20. printf("| | | | | | |\n");
  21. for(i=18;i<=23;i++) {printf("| %d-%d ",pLife[i],pType[i]);} printf("|\n");
  22. printf("| | | | | | |\n");
  23. printf("|-----+-----+-----+-----+-----+-----|\n");
  24. printf("| | | | | | |\n");
  25. for(i=24;i<=29;i++) {printf("| %d-%d ",pLife[i],pType[i]);} printf("|\n");
  26. printf("| | | | | | |\n");
  27. printf("|-----+-----+-----+-----+-----+-----|\n");
  28. printf("| | | | | | |\n");
  29. for(i=30;i<=35;i++) {printf("| %d-%d ",pLife[i],pType[i]);} printf("|\n");
  30. printf("| | | | | | |\n");
  31. printf("*-----------------------------------*\n\n");
  32. }
  33. void manualEntry(int pLife[],int pType[],int pPos,int wantedLife,int wantedType) { //input at position X , Life Y and Type Z
  34. pLife[pPos]=wantedLife;
  35. pType[pPos]=wantedType;
  36. }
  37. void resetBoardLife(int pLife[],int wantedLife) { //modify all 36 board square Life.
  38. short i;
  39.  
  40. for(i=0;i<=35;i++) {
  41. pLife[i]=wantedLife;
  42. }
  43. }
  44. void resetBoardType(int pType[],int wantedType) {//modify all 36 board square Type
  45. short i;
  46.  
  47. for(i=0;i<=35;i++) {
  48. pType[i]=wantedType;
  49. }
  50. }
  51. void boardPOut(int pType[],int pLife[],int pOut[36][36],int pOutLength[]) { //=NEEDED FOR solver1= Used to get all 36 square's pOut list (list of moves that it can play if hitted
  52. int i;
  53.  
  54. for(i=0;i<36;i++) {
  55. if(pLife[i]>0) {
  56. moveList(pType[i],i,pOut,pOutLength);
  57. }
  58. }
  59. }
  60. void setStartingPosition(int startingPosition[],int *startingPositionAmount) {// =NEEDED FOR solver1= define solver1 loop starting locations (the only first pieces to be played)
  61. int i=0;
  62. int exitArray=1;
  63. int enteredValue1;
  64.  
  65. printf("%d: ",i+1);
  66. scanf("%d",&enteredValue1);
  67. startingPosition[i]=enteredValue1;
  68. do {
  69. printf("Add more?(YES=1 NO=0)");
  70. scanf("%d",&exitArray);
  71.  
  72. i+=1;
  73. if(exitArray==1) {
  74. printf("%d: ",i+1);
  75. scanf("%d",&enteredValue1);
  76. startingPosition[i]=enteredValue1;
  77. } else {
  78. *startingPositionAmount=i;
  79. }
  80. } while(exitArray==1);
  81. printf("\n");
  82. }
  83. void solver1(int pLife[],int pOut[36][36],int pOutLength[],int startingPosition[],int startingPositionAmount,int bestPath[36],int *bestPathLength) { //Find the longest bestPathLength and output bestPath[] with it.
  84. int i,x,a,b,c,d,e;
  85. int currentPos; //This points to the active currentPath, starting position are the only currentPath[0] for example
  86. int currentPath[36]; //The current paths are in this,
  87. int dummyPLife[36]; //this is just a copy of the pLife array (which store each board square life)
  88.  
  89. for(e=0;e<36;dummyPLife[e]=pLife[e],e++);
  90. *bestPathLength=0;
  91.  
  92. for(i=0;i<startingPositionAmount;i++){ //this is the first loop, its to get all currentPath[0] from starting locations
  93. if(dummyPLife[startingPosition[i]]>0) { //if that piece life is >0 continu..
  94. currentPath[currentPos]=startingPosition[i]; //then put this valid piece in currentPath[0]
  95. dummyPLife[startingPosition[i]]-=1; //reduce by 1 life so its not played anymore
  96.  
  97. currentPos+=1; //update currentPos
  98. for(x=0;x<999;x++) { //main loop, X gets changed to 0 if a new piece can be played, or a previous value if it gets decreased
  99. if(currentPos==0){ //exit this loop if currentPos is at 0 because only starting position are at 0
  100. break;
  101. }
  102. if(x<pOutLength[currentPath[currentPos-1]]) { //=ERROR IS HERE=if X is smaller than the pOutLength of the previous currentPath continu..
  103. if(dummyPLife[pOut[currentPath[currentPos-1]][x]]>0) { //life is >0? go up 1 level
  104. currentPath[currentPos]=pOut[currentPath[currentPos-1]][x]; //save currentPath
  105. dummyPLife[currentPath[currentPos]]-=1; //reduce 1 dummyPLife
  106.  
  107. currentPos+=1; //new currentPos
  108. x=0; //reseted to 0 for loop
  109. }
  110. } else { //go down 1 level but there is no more moves on this square
  111. if(currentPos>*bestPathLength) { //update bestPathLength and bestPath (if its better)
  112. *bestPathLength=currentPos;
  113. for(a=0;a<*bestPathLength;a++) {
  114. bestPath[a]=currentPath[a];
  115. }
  116. }
  117. currentPos-=1; //currentPos lower by 1 to backtrack
  118. dummyPLife[currentPath[currentPos]]+=1; //put back latest dummyPLife since its not played anymore
  119. for(c=0;c<pOutLength[currentPath[currentPos]];c++) { //search the X the currentPath, if it matchs, x=c
  120. if(currentPath[currentPos]==pOut[currentPath[currentPos]][c]) {
  121. x=c;
  122. break;
  123. }
  124. }
  125. }
  126. }
  127. }
  128. }
  129. printf("\n"); //output solution =)
  130. printf("bestPathLength = %d\n",*bestPathLength);
  131. printf("%d",bestPath[0]);
  132. for(d=1;d<*bestPathLength;d++) {
  133. printf("-%d",bestPath[d]);
  134. }
  135. }
  136.  
  137. int main(int argc,char *argv[]) { // main is simply used for the command entry for console
  138. int quit=0;
  139. int pLife[36];
  140. int pType[36];
  141. int startingPosition[36];
  142. int startingPositionAmount=0;
  143. int pOut[36][36];
  144. int pOutLength[36];
  145. int i;
  146. int bestPath[36];
  147. int bestPathLength;
  148.  
  149. printf("Welcome...\n");
  150. resetBoardLife(pLife,0);
  151. resetBoardType(pType,0);
  152. showBoard(pLife,pType);
  153. do {
  154. int enteredCommand;
  155. int enteredValue1;
  156. int enteredValue2;
  157. int enteredValue3;
  158.  
  159. printf("+----(1)----+----(2)----+-----(3)------+-----(4)------+---(5)---+\n");
  160. printf("|manualEntry|setStartPos|resetBoardLife|resetBoardType| solver1 |\n");
  161. printf("+====(6)====+====(7)====+=====(8)======+=====(9)======+===(10)==+\n");
  162. printf("| | boardPOut | | moveList | |\n");
  163. printf("+----(11)---+----(12)---+-----(13)-----+-----(14)-----+--(15)---+\n");
  164. printf("| | | | | quit |\n");
  165. printf("+-----------+-----------+--------------+--------------+---------+\n");
  166. scanf("%d",&enteredCommand);
  167. switch (enteredCommand) {
  168. case 1:printf("Location:");
  169. scanf("%d",&enteredValue1);
  170. printf(" pLife:");
  171. scanf("%d",&enteredValue2);
  172. printf(" pType:");
  173. scanf("%d",&enteredValue3);
  174. manualEntry(pLife,pType,enteredValue1,enteredValue2,enteredValue3);
  175. break;
  176. case 2:setStartingPosition(startingPosition,&startingPositionAmount);
  177. break;
  178. case 3:printf(" pLife:");
  179. scanf("%d",&enteredValue1);
  180. resetBoardLife(pLife,enteredValue1);
  181. break;
  182. case 4:printf(" pType:");
  183. scanf("%d",&enteredValue1);
  184. resetBoardType(pType,enteredValue1);
  185. break;
  186. case 5:solver1(pLife,pOut,pOutLength,startingPosition,startingPositionAmount,bestPath,&bestPathLength);
  187. break;
  188. case 7:
  189. boardPOut(pType,pLife,pOut,pOutLength);
  190. break;
  191. case 9:printf("pType(0-8):");
  192. scanf("%d",&enteredValue1);
  193. printf("pPosition(0-35):");
  194. scanf("%d",&enteredValue2);
  195. moveList(enteredValue1,enteredValue2,pOut,pOutLength);
  196. break;
  197. case 15:quit=1;
  198. break;
  199. default:printf("error\n\n");
  200. }
  201. showBoard(pLife,pType);
  202. } while(quit==0);
  203. return 0;
  204. }
Is this good? =P
The best i could do for relevant comments!
Ah and function moveList is this http://s219376922.onlinehome.us/misc/moveList.txt
Last edited by Vao; Jun 27th, 2008 at 12:01 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 3
Reputation: Vao is an unknown quantity at this point 
Solved Threads: 0
Vao Vao is offline Offline
Newbie Poster

Re: access violation(segmentational fault) gah

 
0
  #4
Jun 27th, 2008
Problem solved. in function solver1, I replaced:
int currentPos;
by:
int currentPos=0;

I had assumed that C ints were set to 0 per default, Seems not. ~ :]
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 251
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: access violation(segmentational fault) gah

 
0
  #5
Jun 27th, 2008
only static and global variables are set to 0 by default.

ssharish.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum


Views: 475 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC