Thread: I am converting this Java prog to C, need some help

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    14

    I am converting this Java prog to C, need some help

    This program was originally written in Java, but I have converted everything except: 'printf(Integer.toBinaryString(iNum));'

    What would I change that to? This is an integer to binary program. I apologize, I am a newb at this.

    Code:
    #include <stdio.h>
    #include <c:\learning.h>
    
    int main()
    {
    
    			int iNum;
    			printf("Please enter a positive integer, or press 0 to quit\n\n");
    			scanf("%d",&iNum);
    
    			while ( iNum != 0)
    			{
    			
    				printf(Integer.toBinaryString(iNum));
    				printf("Enter another integer or 0 to quit\n\n");
    				scanf("%d",&iNum);
    				
    			}
    		
    
    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    There is no standard function to do convert something to binary like that, you'll need to write your own. There are plenty of samples on these forums, try doing a search and see what you can find.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    102
    Saravanan.T.S.
    Beginner.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    14

    Re: Suggestions

    Originally posted by saravanan_ts
    Hi man,
    Visit this
    http://cboard.cprogramming.com/showt...threadid=42817
    Edit:

    I found it using search, thanks everyone. I will be needing your help later probably.
    Last edited by Kons; 08-07-2003 at 06:56 AM.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    In order to learn, as opposed to simply copy/pasting code, I'd suggest you look at Prelude's version in the thread already mentioned. Understand what it's doing, adapt it to suit your needs (it doesn't do what you want, but it's very close), and then incorporate it into your code.

    >>printf ("%d in binary is %s\n", num, IntToBin(num));
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User
    Join Date
    Jul 2003
    Posts
    102
    Hi man,
    Here is the thing.
    Code:
    #include <stdio.h>
    #include<stdlib.h>
    int main()
    {
    
    			int iNum;
    			char str[10];
    			printf("Please enter a positive integer, or press 0 to quit\n\n");
    			scanf("%d",&iNum);
    
    			while ( iNum != 0)
    			{
    				itoa(iNum,str,10);
    				//call my function here//pass str as parameter.get return value in a pointer or char array.								
    				printf("Enter another integer or 0 to quit\n\n");
    				scanf("%d",&iNum);
    				
    			}
    		
    
    }
    Saravanan.T.S.
    Beginner.

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    14
    Thanks guys, I figured it out with your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Java Prog help with battleship game
    By mars_red in forum Game Programming
    Replies: 2
    Last Post: 02-10-2008, 10:31 AM
  2. Tips for converting C prog. to C++?
    By eccles in forum C++ Programming
    Replies: 7
    Last Post: 01-15-2005, 07:38 AM
  3. C#, Java, C++
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-05-2004, 02:06 PM
  4. The Java language is being expanded
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 06-11-2004, 09:07 PM
  5. converting from java
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2001, 11:17 AM