Thread: space between input

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    12

    Unhappy space between input

    Hello I have a problem I want to print 3 spaces between the output given the code

    Code:
    #include <stdio.h>
    int main (void)
    {
    //Local Declaration
    	int intNum;
    	int oneDigit;
    	int threeDigit;
    	int twoDigit;
    
    //Statements
    	printf("Enter an integral number: ");
    	scanf("&#37;d", &intNum);
    	
    	oneDigit = intNum % 10;
    	twoDigit = intNum % 100;
    	threeDigit = intNum % 1000;
    	
    	printf("0%d\n",intNum);
    	printf("%d\n",intNum);
    	printf("%d\n", threeDigit);
    	printf("%d\n", twoDigit);
    	printf("%d\n", oneDigit);
    	
    	return 0;
    }*/
     //main


    The out put is
    Code:
    01234
    1234
    234
    34
    4
    The output should be
    Code:
    0   1   2   3   4
    1   2   3   4
    2   3   4
    3   4
    4
    how can I do this?
    Thank you dNNNY
    Last edited by Dave_Sinkula; 07-15-2008 at 12:26 PM. Reason: Added code tags to preserve whitespace.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    How about just
    printf("something something");
    Note spaces ^
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    So you probably didn't write this code. Put a space in the format string for your printf() calls.

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    12
    Quote Originally Posted by MacGyver View Post
    So you probably didn't write this code. Put a space in the format string for your printf() calls.
    I did write it
    The question was
    write a program that prompts the user for an integer value between 0 62767 then prints the individual digits with 3 spaces between the digits.The first line is to start with the leftmost digit and print all 5 digits, the second line is to start with the second digit from the left and print 4 digits and so fourth.
    I wrote this code but I we have not covered this so far in the class. I am new to this
    Last edited by dNNNY; 07-15-2008 at 12:33 PM.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by dNNNY View Post
    I did write it
    The question was
    write a program that prompts the user for an integer value between 0 62767 then prints the individual digits with 3 spaces between the digits.The first line is to start with the leftmost digit and print all 5 digits, the second line is to start with the second digit from the left and print 4 digits and so fourth.
    I wrote this code but I find we have not covered this so far in the class. I am new to this
    Look at your printf statements. The program prints whatever is in the quotes. Do you see spaces inside those quotes?

  6. #6
    FOSS Enthusiast
    Join Date
    Jun 2008
    Posts
    64
    I think there's no such function or format string. Write a loop that prints one digit after another. A little hint, modulo is needed here. When dividing the number with 10, the remainder is the last digit; dividing the number with 100 leaves the last two digits as remainder, and so on...

    It's not that hard and it's imho a common exercise in school when beginning with programming.

    Edit: I just realised that you already have some modulo there. But you still need the loop, because printf() can't print an int containing 1234 as "1 2 3 4".
    Last edited by mkruk; 07-15-2008 at 12:44 PM.

  7. #7
    Registered User
    Join Date
    Jul 2008
    Posts
    12
    the number is inputed all at the same time
    "enter a integer" 1234
    If I put a space it will print " 1234"
    I want it to print "1 2 3 4"

    the question is asking me
    write a program that prompts the user for an integer value between 0 62767
    then prints the individual digits with 3 spaces between the digits
    Last edited by dNNNY; 07-15-2008 at 12:46 PM.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by dNNNY View Post
    the number is inputed all at the same time
    "enter a integer" 1234
    If I put a space it will print " 1234"
    I want it to print "1 2 3 4"
    Yes. Good. So don't print the number -- print the digits! That's what you spent all that time picking off oneDigit and twoDigit and threeDigit (and hint: you very well may need a fourDigit) for.

  9. #9
    Registered User
    Join Date
    Jul 2008
    Posts
    12
    oh I get it
    Thank you and thanks for not being rude

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading input problems
    By gonzad in forum C Programming
    Replies: 1
    Last Post: 08-26-2008, 04:00 AM
  2. large program code ,please help
    By Ash1981 in forum C Programming
    Replies: 14
    Last Post: 01-30-2006, 06:16 AM
  3. Custom Made Safe Input Function
    By Beast() in forum C Programming
    Replies: 6
    Last Post: 08-21-2004, 10:19 PM
  4. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM
  5. someone who is good at finding and fixing bugs?
    By elfjuice in forum C++ Programming
    Replies: 8
    Last Post: 06-07-2002, 03:59 PM