January 15, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2585

           Summary: std.stream readf
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: fmfrodrigues@gmail.com


/*
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.*/


-- 

January 15, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2585





------- Comment #1 from fmfrodrigues@gmail.com  2009-01-15 10:27 -------
(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.


--