Solved

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

Posted on 2003-03-18
Medium Priority
247 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
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

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.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
###### Suggested Courses
Course of the Month15 days, 7 hours left to enroll