/*
I dont know if this is a bug... but its a strange behavior...
readf documentation:
abstract int readf(...);
Scan a string from the input using a similar form to C's scanf and std.format.
*/
/*
Content of file that is opened:
1-2-3-4
*/
/*C sample*/
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *fp = fopen(argv[1],"r");
int num[4];
int res = fscanf(fp,"%d-%d-%d-%d",&num[0],&num[1],&num[2],&num[3]);
printf("\n%d-%d-%d-%d %d",num[0],num[1],num[2],num[3],res);
fclose(fp);
return 0;
}
/* Output */
1-2-3-4 4
/*D sample (dmd 1.034 linux)*/
import std.stdio;
import std.stream;
int main(string[] args)
{
File f = new File(args[1], FileMode.In);
int num[4];
TypeInfo[] types = [typeid(int)];
int res = f.readf("%d-%d-%d-%d",&num[0],&num[1],&num[2],&num[3]);
printf("\n%d-%d-%d-%d %d",num[0],num[1],num[2],num[3],res);
f.close();
return 1;
}
/* Output */
1-2-3-0 3
/* if i put a empty space at end of file content all works fine.*/
Comment #1 by fmfrodrigues — 2009-01-15T10:27:48Z
(In reply to comment #0)
> /*
> I dont know if this is a bug... but its a strange behavior...
> readf documentation:
> abstract int readf(...);
> Scan a string from the input using a similar form to C's scanf and std.format.
> */
>
> /*
> Content of file that is opened:
> 1-2-3-4
> */
>
> /*C sample*/
> #include <stdio.h>
>
>
> int main(int argc, char *argv[])
> {
> FILE *fp = fopen(argv[1],"r");
> int num[4];
> int res = fscanf(fp,"%d-%d-%d-%d",&num[0],&num[1],&num[2],&num[3]);
> printf("\n%d-%d-%d-%d %d",num[0],num[1],num[2],num[3],res);
> fclose(fp);
> return 0;
> }
> /* Output */
> 1-2-3-4 4
>
> /*D sample (dmd 1.034 linux)*/
>
> import std.stdio;
> import std.stream;
>
> int main(string[] args)
> {
> File f = new File(args[1], FileMode.In);
> int num[4];
> TypeInfo[] types = [typeid(int)];
> int res = f.readf("%d-%d-%d-%d",&num[0],&num[1],&num[2],&num[3]);
> printf("\n%d-%d-%d-%d %d",num[0],num[1],num[2],num[3],res);
> f.close();
> return 1;
> }
>
> /* Output */
> 1-2-3-0 3
>
> /* if i put a empty space at end of file content all works fine.*/
>
Sorry... The version of dmd i am using is 1.030 and not 1.034.
Comment #2 by andrei — 2015-11-03T19:17:17Z
It's unlikely this D1 issue will get worked on. If it applies to D2 as well and/or if anyone plans to work on it, please reopen.