Page 1 of 1

Compil error in Code C

Posted: Mon Dec 03, 2007 2:10 am
by MIKE_31
I am beginner in language C

I create a function to translate string (ex:"10110") in a integer ,but compilation is on error in the first line:

bintodec.c(1): error: missing semicolon
bintodec.c(1): error: failure

here is by function :

int Bintodec (char* IN)
{
char I;
char X;
int RESULT;
char LEN;
char DIG;
char P[10];
char DIGIT;

I = 0;
X = 0;
RESULT = 0;
LEN = 0;
DIG = 0;

LEN = Length$(IN);

X = LEN - 1;
P[0] = 1;
P[1] = 2;
P[2] = 4;
P[3] = 8;
P[4] = 16;
P[5] = 32;
P[6] = 64;
P[7] = 128;


while( I < LEN )
{
DIGIT = Mid (IN,X,1);
DIG = Asc(DIGIT);

DIG = DIG - 48;
RESULT = RESULT + ( DIG * P );
I = I + 1;
X = X - 1;

}

return (RESULT);

}

Can someone help me ?

Posted: Mon Dec 03, 2007 2:07 pm
by Steve
Hello,

Are you using Flowcode? If so, where is this code?

Also, the line LEN = Length$(IN); will not work because there is no in-built Length$ function in C.

Posted: Mon Dec 03, 2007 3:53 pm
by MIKE_31
Hello,
Yes a use Flowcode V3 Professionnal,
This code is in a file bintodec.c ,I added
char BIN_TO_DEC(char IN); to the definition and
#include "bintodec.c" in the suppementary code.

I went to use this code like a function in My main program like:
FCV_B = bintodec(FCV_data); (data = string and B as integer)

Michel

Posted: Mon Dec 03, 2007 4:37 pm
by Steve
The edits you will need to make are:

1) Put the following code into the "definitions" box of the "supplementary code" window:

Code: Select all

int Bintodec(char* IN);
#include "bintodec.c"
2) In a C icon within your program, call the function like this:

Code: Select all

FCV_B = Bintodec(FCV_DATA);
Note that C is case-sensitive, so you need to be exact.

For some reason, the compiler is refusing to accept the array variable "P" in your C file - change this to "PP" and it is ok.

Also, there are 3 lines in your C code that will not compile:

Code: Select all

LEN = Length$(IN);

DIGIT = Mid (IN,X,1);
DIG = Asc(DIGIT);
You will need to write your own code for these functions.