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

Posted on 2003-03-18
Medium Priority
Last Modified: 2010-04-02
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));
               sum_bin = sum_bin;
     sum = int(sum_bin);

Question by:e_chaos
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
  • Learn & ask questions

Expert Comment

ID: 8157714
you are missing some decleration or library

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

Expert Comment

by:Mayank S
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 [] ) ;


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[] )


int CTOBIN ( char * genes2 )

Hope that helps!


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:

Answered by: cmaryus

Please leave any comments here within the next seven days.


EE Cleanup Volunteer

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question