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 6351263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:58:13+00:00 2026-05-24T21:58:13+00:00

import std.stdio; void main(){ int n; while(readf("%d", &n)){ if(n == 11) break; writeln(n); }

  • 0
import std.stdio;

void main(){

  int n;
  while(readf("%d", &n)){
    if(n == 11)
      break;
    writeln(n);
  }
}

The first iteration works, and it prints n, but after that readf() never returns.

The documentation has only a single line explaining readf():

uint readf(A…)(in char[] for­mat, A args);

   For­mat­ted read one line from stdin.

Am I do something wrong? or is there something wrong with readf()? I just need to read numbers from the standard input.

using: DMD 2.054 64-bit

  • 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-05-24T21:58:14+00:00Added an answer on May 24, 2026 at 9:58 pm

    I believe it’s because readf handles spaces differently than scanf in C. You need to explicitly read in the spaces, so change readf("%d", &n) to readf("%d ", &n) and it should work (hopefully).

    Here’s a quote from Andrei, who implemented the function:

    This is by design. The example works when modified as follows:

    import std.stdio;

    void main() {
    int i, j;
    readf(“%s”, &i);
    readf(” %s”, &j);
    }

    The space before the second parameter tells readf to read and skip all
    whitespace before attempting conversion.

    I’ve implemented readf to be a fair amount more Nazi about whitespace
    than scanf in an attempt to improve its precision. Scanf has been
    famously difficult to use for complex input parsing and validation,
    and I attribute some of that to its laissez-faire attitude toward
    whitespace. I’d be glad to relax some of readf’s insistence on precise
    whitespace handling if there’s enough evidence that that serves most
    of our users. I personally believe that the current behavior (strict
    by default, easy to relax) is best.

    http://www.digitalmars.com/d/archives/digitalmars/D/bugs/Issue_4656_New_stdio.readf_does_not_ignore_white_space_24214.html

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

Sidebar

Related Questions

Hello World for D looks like this: import std.stdio; void main(string[] args) { writeln(Hello
Testing the following in D import std.stdio; struct S { int _val; @property ref
import java.lang.Math; public class NewtonIteration { public static void main(String[] args) { System.out.print(rootNofX(2,9)); }
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateDemo { public static void main(String[]
import java.io.*; import java.util.Scanner; import java.util.StringTokenizer; public class Filereader { public static void main(String[]
I have the following code in D import std.stdio; class Thing { // Fields
Consider the following code: module ftwr; import std.regex; import std.stdio; import std.conv; import std.traits;
import std.stdio; struct Vector2 { float x, y; this (float x, float y) {
i did this code : from scitools.std import * npoints=10 vectorpoint=array(random.uniform(-1,1,[1,2])) experiment=array(random.uniform(-1,1,[npoints,2])) print(vectorpoint=,vectorpoint) print(experiment=,experiment)
I did this code: from scitools.std import * from sympy import * x=Symbol('x') #Integral

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.