hallo i wrote a program with 3 different functions.
something wrong with her and i cant see it.

#include<stdio.h>
int devide9(int num);
int decimal_binar(int num);
int binar_decimal(int num);
int main()
{
int menu, num9, numd1, numb1, numd2, numb2, numfinal1;

	printf("\nHallo these are your options:\n");
	printf("1. Check if your number can be devide by 9 without residue.\n");
	printf("2. Decimal - binar converter.\n");
	printf("3. Binar - decimal converter.\n");
	printf("4. Exit.\n");
	scanf("%i", &menu);
	
	switch (menu)
	{
		case 1:
			printf("please enter a number:\n");
			scanf("%i", &num9);
			numfinal1 = devide9(num9);
			if (numfinal1 == 9)
				printf("the number can be devided by 9.\n");
			else
				printf("the number can not be devided by 9.\n");
			main();
		case 2:
			printf("please enter a number:\n");
			scanf("%i", &numd1);
			numb1 = decimal_binar (numd1);
			if (numd1<0)
				printf("%i (base 10) => -%i (base 2)\n", &numd1, &numb1);
			else
				printf("%i (base 10) => %i (base 2)\n", &numd1, &numb1);
			main();
		case 3:
			printf("please enter a number:\n");
			scanf("%i", &numb2);
			numd1 = binar_decimal(numb2);
			if (numd2<0)
				printf("%i (base 2) => -%i (base 10)\n", &numb2, &numd2);
			else
				printf("%i (base 2) => %i (base 10)\n", &numb2, &numd2);
			main();
		case 4:
			return(0);
			break;
		default: main(); break;

	}
	return(0);
}

int devide9 (int num)
{ 
	int numT, num1;
	if (num<0)
		num = num*-1;
	numT = 0;
	while (num > 0 );
	{
		num1 = num%10;
		numT = num1 + numT;
		num = num/10;
	}
	if (numT>9)
		numT = devide9 (numT);
	return (numT);
}

int decimal_binar (int num)
{	
	int counter, multi, i, numT, num1, numd1;
	if (num<=1023 && num >= -1023)
	{
	if (num<0)
		num = num*-1;
	counter = 0;
		numT = 0;
		while (num > 0 );
		{
			num1 = num % 2;
			num = num / 2;
			if (counter == 0)
				numT = num1;
			else
			{
				multi = 1;
				for (i=1; i<=counter; i++)
				{
					multi = 10 * multi;
				}
			}
			numT = multi * num1 + numT;
			counter = counter +1;
		}
	}
	else
	{
			printf("please enter a new number:\n");
			scanf("%i", &numd1);
			numT = decimal_binar(numd1);
	}
	return (numT);
}


int binar_decimal (int num)
{
	int num1, counter, hez1, hezT, i,numT, numb1;
	counter = 0;
	if (num >= -1111111111 && num <= 1111111111)
	{
		if (num < 0)
			num = num*-1;
		counter = 0;
		numT = 0;
		while (num > 0 );
		{
			num1 = num % 10;
			hez1 = hezT = 1;
			for (i=1; i<=counter; i++) 
			{
				hez1 = hezT;
				hezT = hez1*2;
			}
		numT = num1*hezT + numT;
		counter = counter + 1;
		num = num / 10;
		}
	}
	else
	{
		printf("please enter a new number:\n");
		scanf("%i", &numb1);
		numT = binar_decimal (numb1);
	}
	return (numT);
}

Dani AI

Generated

Quick checklist (fast fixes first)

  • The POLINK "Access is denied" message normally means the linker couldn't write the program file. The usual culprits are: an earlier run of your program is still running (so the .exe is locked), an antivirus/locker is holding the file, or you lack write permissions in the folder. As suggested, check and terminate the program process (Task Manager / taskkill) or try compiling to a different output name or directory. If the file cannot be deleted/renamed, something still has it open.

Why your program can stay running (and block rebuilding)

  • Recursive calls to main() and missing break statements cause uncontrolled flow and can easily leave the program stuck or spun in loops. Also check for accidental empty loops caused by a stray semicolon after a loop header (this makes the loop body no longer execute and can create an infinite loop). Uninitialized or mismatched variables and passing an address to printf instead of the value will produce wrong output and undefined behavior. and were right to advise against calling main() repeatedly — replace that pattern with a proper loop.

Practical fixes and a safe menu pattern

  • Replace recursive menu calls with a single loop and break/return from cases. Initialize variables before use. Make sure printf("%d", x) receives x, not &x. Compile with warnings enabled (e.g. -Wall -Wextra) and fix every warning. Use a debugger or add small trace prints to see where execution never returns. Example menu skeleton:
    
    #include <stdio.h>

int main(void) {
int menu;
while (1) {
puts("1) Divisible by 9\n2) Dec->Bin\n3) Bin->Dec\n4) Exit");
if (scanf("%d", &menu) != 1) break;
switch (menu) {
case 1: / handle / break;
case 2: / handle / break;
case 3: / handle / break;
case 4: return 0;
default: puts("Invalid choice"); break;
}
}
return 0;
}



Extra troubleshooting tips
- If POLINK persists after killing the process: try compiling to a different filename, run the compiler as your user (or admin if building into protected folders), temporarily disable antivirus, and rerun with a debugger attached to confirm no infinite loops. Address the coding issues above first — they are the most common reason the executable remains running and blocks subsequent builds.

Recommended Answers

All 5 Replies

Use code tags and indent your code properly.

> 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.

main() function cannot be called again and again.
Instead you can use another function in place of it or use

goto label;

main() function cannot be called again and again.
Instead you can use another function in place of it or use

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.