You sure your teacher wrote that code?
Here's the function fixed:
Code:
typedef struct
{
char digit[100];
int signbit;
int last_digit;
} big_num;
void ch_to_bignum( char*s,big_num*n )
{
int i;
if(s[0]!='-')
{
n->signbit='+';
i=0;
}
else
{
i=1;
n->signbit='-';
}
strcpy(n->digit,&s[i]);
n->last_digit=strlen(n->digit);
}
There were tones of mistakes! From misnaming variables, missing ;'s, spaces in variables not to mention the indenting!
Use it like this:
Code:
int main( void )
{
big_num m1;
char *test_ch = "242";
ch_to_bignum( test_ch, &m1 );
cout<< m1.digit << '\n'
<< m1.last_digit << '\n'
<< m1.signbit << '\n';
return 0;
}