943,851 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1546
  • C RSS
Dec 15th, 2008
0

a program i wrote and gives me all the time: POLINK: fatal error: Access is denied.

Expand Post »
hallo i wrote a program with 3 different functions.
something wrong with her and i cant see it.
  1. #include<stdio.h>
  2. int devide9(int num);
  3. int decimal_binar(int num);
  4. int binar_decimal(int num);
  5. int main()
  6. {
  7. int menu, num9, numd1, numb1, numd2, numb2, numfinal1;
  8.  
  9. printf("\nHallo these are your options:\n");
  10. printf("1. Check if your number can be devide by 9 without residue.\n");
  11. printf("2. Decimal - binar converter.\n");
  12. printf("3. Binar - decimal converter.\n");
  13. printf("4. Exit.\n");
  14. scanf("%i", &menu);
  15.  
  16. switch (menu)
  17. {
  18. case 1:
  19. printf("please enter a number:\n");
  20. scanf("%i", &num9);
  21. numfinal1 = devide9(num9);
  22. if (numfinal1 == 9)
  23. printf("the number can be devided by 9.\n");
  24. else
  25. printf("the number can not be devided by 9.\n");
  26. main();
  27. case 2:
  28. printf("please enter a number:\n");
  29. scanf("%i", &numd1);
  30. numb1 = decimal_binar (numd1);
  31. if (numd1<0)
  32. printf("%i (base 10) => -%i (base 2)\n", &numd1, &numb1);
  33. else
  34. printf("%i (base 10) => %i (base 2)\n", &numd1, &numb1);
  35. main();
  36. case 3:
  37. printf("please enter a number:\n");
  38. scanf("%i", &numb2);
  39. numd1 = binar_decimal(numb2);
  40. if (numd2<0)
  41. printf("%i (base 2) => -%i (base 10)\n", &numb2, &numd2);
  42. else
  43. printf("%i (base 2) => %i (base 10)\n", &numb2, &numd2);
  44. main();
  45. case 4:
  46. return(0);
  47. break;
  48. default: main(); break;
  49.  
  50. }
  51. return(0);
  52. }
  53.  
  54. int devide9 (int num)
  55. {
  56. int numT, num1;
  57. if (num<0)
  58. num = num*-1;
  59. numT = 0;
  60. while (num > 0 );
  61. {
  62. num1 = num%10;
  63. numT = num1 + numT;
  64. num = num/10;
  65. }
  66. if (numT>9)
  67. numT = devide9 (numT);
  68. return (numT);
  69. }
  70.  
  71. int decimal_binar (int num)
  72. {
  73. int counter, multi, i, numT, num1, numd1;
  74. if (num<=1023 && num >= -1023)
  75. {
  76. if (num<0)
  77. num = num*-1;
  78. counter = 0;
  79. numT = 0;
  80. while (num > 0 );
  81. {
  82. num1 = num % 2;
  83. num = num / 2;
  84. if (counter == 0)
  85. numT = num1;
  86. else
  87. {
  88. multi = 1;
  89. for (i=1; i<=counter; i++)
  90. {
  91. multi = 10 * multi;
  92. }
  93. }
  94. numT = multi * num1 + numT;
  95. counter = counter +1;
  96. }
  97. }
  98. else
  99. {
  100. printf("please enter a new number:\n");
  101. scanf("%i", &numd1);
  102. numT = decimal_binar(numd1);
  103. }
  104. return (numT);
  105. }
  106.  
  107.  
  108. int binar_decimal (int num)
  109. {
  110. int num1, counter, hez1, hezT, i,numT, numb1;
  111. counter = 0;
  112. if (num >= -1111111111 && num <= 1111111111)
  113. {
  114. if (num < 0)
  115. num = num*-1;
  116. counter = 0;
  117. numT = 0;
  118. while (num > 0 );
  119. {
  120. num1 = num % 10;
  121. hez1 = hezT = 1;
  122. for (i=1; i<=counter; i++)
  123. {
  124. hez1 = hezT;
  125. hezT = hez1*2;
  126. }
  127. numT = num1*hezT + numT;
  128. counter = counter + 1;
  129. num = num / 10;
  130. }
  131. }
  132. else
  133. {
  134. printf("please enter a new number:\n");
  135. scanf("%i", &numb1);
  136. numT = binar_decimal (numb1);
  137. }
  138. return (numT);
  139. }
Last edited by Narue; Dec 15th, 2008 at 12:16 pm. Reason: added code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
amit.turkaspa is offline Offline
1 posts
since Dec 2008
Dec 15th, 2008
0

Re: a program i wrote and gives me all the time: POLINK: fatal error: Access is denied.

Use code tags and indent your code properly.
Reputation Points: 124
Solved Threads: 18
Junior Poster
devnar is offline Offline
148 posts
since Sep 2008
Dec 15th, 2008
0

Re: a program i wrote and gives me all the time: POLINK: fatal error: Access is denied.

> POLINK: fatal error: Access is denied.
There's a good chance that the previous attempt at this code is still running, and that you can't overwrite a running programs' executable.

Oh, and don't call main() recursively, use a loop.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Dec 26th, 2008
0

Re: a program i wrote and gives me all the time: POLINK: fatal error: Access is denied.

main() function cannot be called again and again.
Instead you can use another function in place of it or use
  1. goto label;
Reputation Points: 6
Solved Threads: 9
Junior Poster in Training
ajay.krish123 is offline Offline
90 posts
since Nov 2008
Dec 26th, 2008
0

Re: a program i wrote and gives me all the time: POLINK: fatal error: Access is denied.

main() function cannot be called again and again.
Instead you can use another function in place of it or use
  1. goto label;
Use of goto is frowned upon. The only place where it's usage is justified is when you're in a nest of loops and wanna come out of it with the least amount of hassle. As Salem has already suggested, loop is the best way to go about this particular problem.
Reputation Points: 124
Solved Threads: 18
Junior Poster
devnar is offline Offline
148 posts
since Sep 2008
Dec 26th, 2008
0

Re: a program i wrote and gives me all the time: POLINK: fatal error: Access is denied.

Click to Expand / Collapse  Quote originally posted by devnar ...
Use of goto is frowned upon. The only place where it's usage is justified is when you're in a nest of loops and wanna come out of it with the least amount of hassle. As Salem has already suggested, loop is the best way to go about this particular problem.
As i already stated above him to use the another function
goto() statements is the last option to use in the program when nothing works.
Reputation Points: 6
Solved Threads: 9
Junior Poster in Training
ajay.krish123 is offline Offline
90 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Please help me
Next Thread in C Forum Timeline: Random number generator





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC