when I run my program in GCC ,there are some problem apperes to me ,,I need help to make it run !!Plz

#include<stdio.h>

#include<stdlib.h>
#include<string.h>
#include<math.h>


   // Declare a few variables 

char InputString[32], type;
int NumValue, sum=0, Length, result;

int main()    //main function
{
printf("Type in a number:");
if(!gets(InputString))         
printf("You did not enter any value:\n");
Length = strlen(InputString); 

if( (result = testnumber())==0 )
{
printf("That is an invalid number!");  // prints That is an invalid number!
exit(0);
}

Asktbase();  //call function Asktbase
//        printf("value of type= %c" , type );

if( (type=='f') &&  (InputString[0]==48))
{
binary_decimal() ; 
exit(0);
}    
    
if(type=='f')
{
printf("Is this number decimal (d) or binary (b)?");
scanf("%c",&type);
if(type=='d') decimal_binary(); 
if(type=='b') binary_decimal(); 
}
else 
{
if( (result = testnumber())==0)
{
printf("That is an invalid number!");
}

Length = strlen(InputString);  //strlen: Find length of string
IsDecimal();

if(type=='d')
{
              if(atoi(InputString)<=255 ) decimal_binary();   //atoi: Convert ASCII string to integer
              else
              {
              printf("That is an invalid number!");
              exit(0);
              }
}
else binary_decimal();
}
}

binary_decimal()   //function to convert binary to decimal number
{
int i, p, a;
for(i=1; i<=Length; i++)
{
if(InputString[Length-i]==49) NumValue=1;
else  NumValue=0; 
                 if(NumValue==1)
                 { 
                 p=i-1;
                 a=pow(2,p);
                 sum=sum+a;
                 }
				 }
printf("Converting binary to decimal. Answer is: %d \n", sum);  // print number binary to decimal
}

decimal_binary()  //function to convert decimal to binary number
{
int dec,i=1,rem,res=0;
dec = atoi(InputString);  // //atoi: Convert ASCII string to integer
   while(dec>0)
    {
	rem=dec%2;
	dec=dec/2;
	res=res+(i * rem);
	i=i*10;
   }
printf("Converting decimal to binary. Answer is: %8.8d",res);    //print number decimal to binary
 }

int testnumber()
{
int i ;      
for(i = 1 ; i <= Length ; i++)
{
if(isdigit(InputString[Length-i]))    //isdigit - test for a decimal digit
return 1 ;    
else return 0 ;                      
}
}

IsDecimal()
{
int i;
for(i = 1 ; i <= Length ; i++)
{

	//ASCII code 50 is equal to Two,51 equal to three, 52 equal to four, 53 equal to five, 54 equal to six, 55 equal to seven, 56 equal to eight, 57 equal to nine

if( ( InputString[Length-i] ==50) ||  ( InputString[Length-i] ==51)||( InputString[Length-i] ==52)||( InputString[Length-i] ==53)
||( InputString[Length-i] ==54)||( InputString[Length-i] ==55)||( InputString[Length-i] ==56)||( InputString[Length-i] ==57))  
type = 'd' ; 
}    
if((InputString[0] ==48) && (type = 'd'))
{
 printf("That is an invalid number!");
 exit(0);
}
}


testbase()
{
int i;
for(i = 1 ; i <= Length ; i++)
{
if( ( InputString[Length-i] !=49) ||  (InputString[Length-i]!=48))  
type = 'd' ; 
}    
}


Asktbase()
{
int i;
for(i = 1 ; i <= Length ; i++)
{
if(   ( InputString[Length-i] ==49) ||  (InputString[Length-i] ==48)   )     //ASCII code 48 is equal to zero and 49 equal to 1
{
    
type='f' ; 
}
else 
{
type='a' ;
Length = i - 1 ;
}
}    
}

-------------
my error
assign1.c: In function `int main()':
assign1.c:19: error: `testnumber' was not declared in this scope
assign1.c:25: error: `Asktbase' was not declared in this scope
assign1.c:30: error: `binary_decimal' was not declared in this scope
assign1.c:38: error: `decimal_binary' was not declared in this scope
assign1.c:39: error: `binary_decimal' was not declared in this scope
assign1.c:43: error: `testnumber' was not declared in this scope
assign1.c:49: error: `IsDecimal' was not declared in this scope
assign1.c:53: error: `decimal_binary' was not declared in this scope
assign1.c:60: error: `binary_decimal' was not declared in this scope
assign1.c: At global scope:
assign1.c:65: error: ISO C++ forbids declaration of `binary_decimal' with no type
assign1.c: In function `int binary_decimal()':
assign1.c:74: warning: converting to `int' from `double'
assign1.c: At global scope:
assign1.c:82: error: ISO C++ forbids declaration of `decimal_binary' with no type
assign1.c: In function `int testnumber()':
assign1.c:100: error: `isdigit' was not declared in this scope
assign1.c: At global scope:
assign1.c:107: error: ISO C++ forbids declaration of `IsDecimal' with no type
assign1.c:127: error: ISO C++ forbids declaration of `testbase' with no type
assign1.c:138: error: ISO C++ forbids declaration of `Asktbase' with no type
>Exit code: 1

I haven't reviewed the whole code, especially since its got no indentation and its not in code tags, but the first error is happening because you have your testnumber() function defined AFTER you first used it. The compiler doesn't know what testnumber() is unless you at least declare it before the first use. It can be defined later on in the code but it must first be declared by writing "int testnumber();" at the top of your C code, or at least move your main() function at the bottom of the page.

My main advice is to learn how to effectively use headers. A well written C program has every C code complimented with a header with all the declarations inside of it which you #include from your C file.

your advice was great ,,, thanks it's been reduce the mistakes to few ,, that what left to me

>"C:\Program Files\gcc\bin/g++" -Os -mconsole -g me.c -o me.exe
me.c:11: error: expected initializer before ')' token
me.c:68: error: ISO C++ forbids declaration of `binary_decimal' with no type
me.c: In function `int binary_decimal()':
me.c:77: warning: converting to `int' from `double'
me.c: At global scope:
me.c:85: error: ISO C++ forbids declaration of `decimal_binary' with no type
me.c: In function `int testnumber()':
me.c:103: error: `isdigit' was not declared in this scope
me.c: At global scope:
me.c:110: error: ISO C++ forbids declaration of `IsDecimal' with no type
me.c:130: error: ISO C++ forbids declaration of `testbase' with no type
>Exit code: 1

Since you changed you code to fix that one bug, now your errors are inconsistent with your original code.

You need to use code tags when you copy your code in here, its very important.

what do you need by code tags?
anyway thanks for your helping
that what left with me ,, do you have hint how to do them

>"C:\Program Files\gcc\bin/g++" -Os -mconsole -g me.c -o me.exe
me.c:11: error: expected initializer before ')' token
me.c: In function `int binary_decimal()':
me.c:78: warning: converting to `int' from `double'
me.c: In function `int testnumber()':
me.c:104: error: `isdigit' was not declared in this scope
>Exit code: 1

On the message box you are typing inside of, there is an icon that saids in big letters Code. You need to use that to put your NEW code inside of. You keep showing errors for code we have not seen yet. Your old code is incompatible with your new errors.

>"C:\Program Files\gcc\bin/g++"  -Os -mconsole -g me.c -o me.exe
me.c:11: error: expected initializer before ')' token
me.c: In function `int binary_decimal()':
me.c:78: warning: converting to `int' from `double'
me.c: In function `int testnumber()':
me.c:104: error: `isdigit' was not declared in this scope
>Exit code: 1

... :|

Well, at least you got the (code) part right...

Hmmm...

How do I explain that the error you keep showing us is for code no one in this entire world can actually see but yourself.

How do I explain that the line numbers in the error messages do not apply to obsolete code?

But more importantly, How do I explain that what I need in the code-tags is not the error, but the CODE ITSELF!

Perhaps its impossible to ever know for sure. A great paradox I suppose.

commented: ;) +1
>"C:\Program Files\gcc\bin/g++"  -Os -mconsole -g me.c -o me.exe
me.c:11: error: expected initializer before ')' token
me.c: In function `int binary_decimal()':
me.c:78: warning: converting to `int' from `double'
me.c: In function `int testnumber()':
me.c:104: error: `isdigit' was not declared in this scope
>Exit code: 1

Just Post your code also inside the code tags.
To help with your issue, members here needs to see the code also.
They cannot guess the code from your errors.

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.