Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8890481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:30:44+00:00 2026-06-14T22:30:44+00:00

In the following if I write scanf with %d /%d (with a space) then

  • 0

In the following if I write scanf with %d /%d" (with a space) then I can input a fraction seperated by spaces.

For example: The input can be 5/7 or 5 /7 or 5 / 7 (with spaces anywhere).

How does scanf in the code below read spaces between numbers that way but yet it is has only one space between %d /%d"?

#include <stdio.h>

int main()
{
   int i, j;
   scanf("%d /%d", &i, &j);
   return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:30:45+00:00Added an answer on June 14, 2026 at 10:30 pm

    Almost all input format specifiers in scanf will automatically skip all whitespace before reading the actual data. E.g. the %d format specifier in scanf actually means <skip spaces> <read int>.

    That means that if we used %d/%d format for reading fractions, it would stand for

    <skip spaces> <read int> <require /> <skip spaces> <read int>
    

    In this sequence we have everything necessary, except we don’t allow/skip spaces before the /. To fix that we have to add an explicit request to skip spaces before /, which in scanf format string is expressed by a space character. Adding a space character before / produces %d /%d format string, which stands for

    <skip spaces> <read int> <skip spaces> <require /> <skip spaces> <read int>
    

    This is exactly what we need and that is exactly what you have in your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code example below. Whereby you can enter a command to
I write the following code all the time to handle when the enter key
I write the following code in simulate.jsp , to receive some String simulationInfos from
If I write the following code: session_start(); $_SESSION['user_id']='daniel'; the variable stays fine as long
I'm learning Haskell and am trying to write code as fast as I can
I wrote the following code: int N; scanf(%d, &N); int i; for (i =
How to write following statement in c using switch statement in c int i
I wanted to write following query through codeigniter's db helper class, guide me plz
I have the following assignment: Write a complete 8086 program to perform the calculator
In my .htaccess file i have the following re-write rule RewriteRule ^([a-z]*)$ work.php?album=$1 [L]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.