digitalmars.D.learn - Need som assistense with readf();
- Mr. P-teo (25/25) Jul 07 2012 So iv just been getting into D programming, im liking it alot so
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (18/30) Jul 07 2012 A space character in the format string reads and ignores any number of
- Mr. P-teo (1/13) Jul 08 2012 Thanks very much, that got it sorted,
So iv just been getting into D programming, im liking it alot so 
far but i have come across one issue that i am unable to find a 
solution for.
Basically whenever i use readf(); to gather console input it wont 
run the program if there is code afterwards.
Here is an example:
import std.stdio;
int main(){
     long number, number2;
     write("Enter an integer: ");
     readf("%d", &number);
     return 0;
}
That works fine, but if i try and imput 2 numbers to seperate 
variables it doesn't work.
import std.stdio;
int main(){
     long number, number2;
     write("Enter an integer: ");
     readf("%d", &number);
     write("another no";
     readf("%d", &number2);
     return 0;
}
can anyone help me.
 Jul 07 2012
On 07/07/2012 03:35 PM, Mr. P-teo wrote:Basically whenever i use readf(); to gather console input it wont run the program if there is code afterwards.readf() does not automatically consume the end-of-line character.That works fine, but if i try and imput 2 numbers to seperate variables it doesn't work. import std.stdio; int main(){ long number, number2; write("Enter an integer: "); readf("%d", &number);A space character in the format string reads and ignores any number of whitespace at that position.write("another no"; readf("%d", &number2); return 0;Just insert spaces before the format specifiers: import std.stdio; int main(){ long number, number2; write("Enter an integer: "); readf(" %d", &number); write("another no"); readf(" %d", &number2); writeln(number, ' ', number2); return 0; } Ali -- D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html
 Jul 07 2012
 Just insert spaces before the format specifiers:
 import std.stdio;
 int main(){
     long number, number2;
     write("Enter an integer: ");
     readf(" %d", &number);
     write("another no");
     readf(" %d", &number2);
     writeln(number, ' ', number2);
     return 0;
 }
 Ali
Thanks very much, that got it sorted,
 Jul 08 2012








 
  
  
  "Mr. P-teo" <dthp18 gmail.com>
 "Mr. P-teo" <dthp18 gmail.com>