Solved

problem in the declaration when converting a binary string back into integer array

Posted on 2003-03-18
Medium Priority
254 Views
i'm working on this code that is supposed convert this binary string into an array of integer consisting of '1's and '0's and then return the decimal value.

my problem is that the builder gave me this line:

unresolved external symbol "int __cdecl CTOBIN(char)" (?CTOBIN@@YAHD@Z)

Can somebody pls kindly advise me on this?

# define BINSIZE 8
int CTOBIN(char genes2);          //convert binary string back into integer

//convert binary string back into integer value
int CTOBIN(char genes2[BINSIZE])
{
int bin_str[BINSIZE];
int sum;
double sum_bin;

for (i = 0; i <7; i++)
{
bin_str[i] = atoi(genes2);
}

for (i = 0; i < 7; i++)
{
if (bin_str[i] == 1)
sum_bin += pow(2, (7 - i));
else
sum_bin = sum_bin;
}

sum = int(sum_bin);

return(sum);
}
0
Question by:e_chaos

LVL 4

Expert Comment

ID: 8157714
you are missing some decleration or library
0

LVL 3

Accepted Solution

cmaryus earned 200 total points
ID: 8157782
in these lines:
>int CTOBIN(char genes2);          //convert binary string back into integer
>
>//convert binary string back into integer value
>int CTOBIN(char genes2[BINSIZE])

int CTOBIN(char genes2) -  you declared with a paramer char
int CTOBIN(char genes2[BINSIZE]) - you implemeted with a parameter ARRAY OF chars

so the thing is that the declaration is not the same as implementation.
do this:

int CTOBIN(char genes2[BINSIZE]);          //convert binary string back into integer

//convert binary string back into integer value
int CTOBIN(char genes2[BINSIZE])
{
...
}

or even :

int CTOBIN(char* genes2);          //convert binary string back into integer

//convert binary string back into integer value
int CTOBIN(char* genes2)
{
...
}

The last one do the same but is the cleanest, you don't have to supply the array size...
0

LVL 30

Expert Comment

ID: 8157817
>> int CTOBIN(char genes2);          //convert binary string back into integer

CTOBIN accepts a character as an argument, and you're violating this in the definition which follows this statement, where you are accepting an array of characters as argument.

As per your need, you have to accept the array as an argument, so make it:

int CTOBIN ( char genes2 [] ) ;

or

int CTOBIN ( char * genes2 ) ;

Now, in the function definition:

>> int CTOBIN(char genes2[BINSIZE])
>> {

You don't need to specify a size here. Make it:

int CTOBIN ( char genes2[] )
{

or

int CTOBIN ( char * genes2 )
{

Hope that helps!

Mayank.
0

LVL 9

Expert Comment

ID: 9510532

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Tinchos
EE Cleanup Volunteer
0

Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.