Architecture problem???....

This is a discussion on Architecture problem???.... within the C Programming forums, part of the General Programming Boards category; So, I have not coded in C for many years. Wrote some simple C code to convert numbers at the ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    2

    Architecture problem???....

    So, I have not coded in C for many years. Wrote some simple C code to convert numbers at the shell prompt many years ago and it always worked fine. Is there an bit architecture bit width issue? I am sure this is simple for people here, but as I am out of practice...sorry....

    Code:
    #include <stdio.h>
    #include <math.h>
    
    main ()
    {
      long i;
      long tmp;
      char bin_str[32+1];
    
      while ((scanf("%lx",&tmp)) != EOF) {
        for (i=0;i<32;i++) {
           bin_str[31-i] = (tmp&(0x01 << i)) ? '1' : '0';
        }
        bin_str[i+1] = '\n';
        printf("%s\n",bin_str);
      }
    }
    -------------------
    So why does the printf continue to run on?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by rjj04 View Post
    So, I have not coded in C for many years. Wrote some simple C code to convert numbers at the shell prompt many years ago and it always worked fine. Is there an bit architecture bit width issue? I am sure this is simple for people here, but as I am out of practice...sorry....

    Code:
    #include <stdio.h>
    #include <math.h>
    
    main ()
    {
      long i;
      long tmp;
      char bin_str[32+1];
    
      while ((scanf("%lx",&tmp)) != EOF) {
        for (i=0;i<32;i++) {
           bin_str[31-i] = (tmp&(0x01 << i)) ? '1' : '0';
        }
        bin_str[i+1] = '\0';
        printf("%s\n",bin_str);
      }
    }
    -------------------
    So why does the printf continue to run on?
    Try that. The scanf() != EOF looks quite dodgy. Perhaps while (scanf() ) with no EOF?

    scanf() returns the number of items it has scanned and stored.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    2
    yes, the backslash newline was the problem... not sure why it did not have a problem before though

    thank you!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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