Thread: any one plz help me

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    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;
    }
    Last edited by twomers; 01-14-2007 at 08:55 AM.

  2. #2
    Registered User
    Join Date
    Jan 2007
    Posts
    35
    Quote Originally Posted by twomers
    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;
    }
    thx buddy but this will not only solve my prob me have to solve long long int calculations

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  3. plz help me with simple string comparison.
    By MegaManZZ in forum C++ Programming
    Replies: 11
    Last Post: 02-18-2008, 01:11 PM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM