I read my program on gcc but have to run on bcc...

This is a discussion on I read my program on gcc but have to run on bcc... within the C Programming forums, part of the General Programming Boards category; but it doesn't work properly on bcc.what am I gonna do??I worked for 5 days for a code but it ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    25

    I wrote my program on gcc but have to run on bcc...

    but it doesn't work properly on bcc.what am I gonna do??I worked for 5 days for a code but it means nothing .....could you check it and tell me what is wrong with it??
    THE code:multiple two numbers 1-250 digits but it's forbidden to use "float" or "double" in the code...

    Code:
    #include <stdio.h>
    #include <string.h>
    
    char multiplicand[251];
    char multiplier[251];
    char input[501];
    
    char x[255];
    char y[255];
    char digit[510];
    char carry[510];
    
    int main(void)
    {
            int m, n;
            char *p;
    
            int i, j;
            int temp;
    
    
            fgets(input, 501, stdin);
            p = strchr(input, '*');
            *p = ' ';
    
            sscanf(input, "%[0123456789] %[0123456789]", multiplicand, multiplier);
    
            m = strlen(multiplicand);
            n = strlen(multiplier);
    
            memset(x, '0', 255);
            memset(y, '0', 255);
    
            memmove(x+(255-m-1), multiplicand, (m+1));
            memmove(y+(255-n-1), multiplier, (n+1));
    
    
    
            memset(digit, '0', 510);
            memset(carry, '0', 510);
    
            for(j = 253; j >= 0; j--) {
                    for(i = 253; i >= 0; i--){
                            temp = (x[i] - '0') * (y[j] - '0') + (carry[i+j+1]-'0');
    
                            digit[i+j+1] += (temp % 10);
                            if(digit[i+j+1]>'9'){
                                    digit[i+j] += (digit[i+j+1]-'0')/10;
                                    digit[i+j+1] = (digit[i+j+1]-'0')%10 + '0';
                            }
                            carry[i+j] += (temp / 10);
                            carry[i+j+1] = '0';
                    }
            }
      puts(digit);           
     return 0;
    }
    please help...I will get zero..
    Last edited by philae; 03-06-2006 at 02:52 PM.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    using VC++ 6.0 compiler on XP:

    I get compile error: error C2065: 'z' : undeclared identifier

    displayed digits instead of z so that it will compile.

    if input is "12 * 5", the result in digits is 6000, or two too-many zers at the end.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    ok, I corrected it,,(look above)
    but still there's sth wrong..

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Post the error message.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,157
    This is the third thread on this same program. Not to mention threads started on other boards. How confused to you really want to get? How many different ideas are you going to try to mash together? I've seen many different solutions to this input problem. And it looks like you're listening to most of them.

    I'm going to assume it's the input that you can't get correct, since you didn't explain what you are still having trouble with. If this is not the case and your input is working, ignore the rest of this post.

    ============================

    Get rid of this stuff, it's simply confusing and too complex:
    Code:
            fgets(input, 501, stdin);
            p = strchr(input, '*');
            *p = ' ';
    
            sscanf(input, "%[0123456789] %[0123456789]", multiplicand, multiplier);
    
            m = strlen(multiplicand);
            n = strlen(multiplier);
    
            memset(x, '0', 255);
            memset(y, '0', 255);
    
            memmove(x+(255-m-1), multiplicand, (m+1));
            memmove(y+(255-n-1), multiplier, (n+1));
    
    
    
            memset(digit, '0', 510);
            memset(carry, '0', 510);
    So far you claim the input is
    1234567*98765
    No spaces. Always one line, 2 numbers, one *. Correct?

    Set up 1st loop -- a while loop
    Use getchar() to read a character at a time.
    If the character is >= '0' AND <= '9' put it in your first number array and immediately subtract '0' to make the value a number.
    Keep doing that until you see the '*' character and you are done with that loop.
    Remember the last array position you filled.

    Set up 2nd loop
    Use getchar() to read a character at a time.
    If the character is >= '0' AND <= '9' put it in your second number array and immediately subtract '0' to make the value a number.
    Keep doing that until you see the '\n' character and you are done with that loop, and your input.
    Remember the last array position you filled.

    Now, starting at the last position filled in each array, start your multiplication phase.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help on making program run more efficiently
    By peeweearies in forum C Programming
    Replies: 2
    Last Post: 03-23-2009, 02:01 AM
  2. program run as service
    By statquos in forum C++ Programming
    Replies: 2
    Last Post: 06-02-2008, 11:43 AM
  3. "sorting news" assignment
    By prljavibluzer in forum C Programming
    Replies: 7
    Last Post: 02-06-2008, 05:45 AM
  4. Replies: 2
    Last Post: 12-22-2006, 07:45 PM
  5. DEV-C++ made program crashes when run from outside the ide
    By rainmanddw in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2006, 09:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21