Thread: Formatted Inputs Question

  1. #1
    Registered User
    Join Date
    May 2017
    Posts
    3

    Formatted Inputs Question

    Hello there, can anyone refer me to what might be an "extensive" guide of formatted input types...

    I'm inputting a 4 digit integer, and I need to access each digit individually. I could convert them and put them in a character array, and then recast them as integers to do math with each individual digit. But I'm sure my professor wants me to do it with "%d"... just can't find anywhere how to access each digit individually. I've tried "%d2" for instance, or "%2d"...I've also tried something like...
    Code:
    printf("%d", 2, encodingInt);
    to see if it would print just the number in the second spot...

    Maybe it's just not possible this way.

    (Just starting C class...)

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Just thought I would say, you're talking about inputs, but printf() is for formatted output. Scanf() is for input. The difference is important.

    Well, anyway, with a 4-digit integer, the second digit is
    Code:
    printf("%d\n", (encodingInt/100)%10);
    printf() doesn't really help you with this, at its heart, it is a math question.
    Last edited by whiteflags; 05-29-2017 at 02:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 12-01-2013, 12:05 PM
  2. A little question about formatted input ..
    By manasij7479 in forum C Programming
    Replies: 1
    Last Post: 10-25-2011, 01:49 AM
  3. How to handle inputs if the user inputs the wrong thing
    By bassist11 in forum C Programming
    Replies: 5
    Last Post: 09-22-2010, 04:28 AM
  4. A little question about formatted output
    By Extropian in forum C Programming
    Replies: 10
    Last Post: 08-19-2005, 08:30 AM
  5. Formatted output question...
    By Lateralus in forum C Programming
    Replies: 3
    Last Post: 06-15-2005, 10:58 AM

Tags for this Thread