On 07.03.2017 16:30, fredvs wrote:
>>> Many thanks Sven for your help.
>>> Do you agree if I add your name into the list of the "great contributors"
>>> of
>>> uos (https://github.com/fredvs/uos) ?
>> I don't think that's necessary. I'm merely doing my "job"...
> 
> OK, I understand. (But I ask it always when I get great help, it is a matter
> of conscience and respect.)
> 
>>> Huh? Of course you can do that rather similary in C as well.
>> Indeed. You can do exactly the same. You can do this: 
> 
> Huh in C, in one shot, like fpc does, without conversion and working?

The following code reads the floatbuf.txt file that my Pascal example
code generated and correctly prints 3.141500 42 times:

=== code begin ===

#include <stdio.h>

int main()
{
        float* floatbuf;
        FILE* file;

        file = fopen("floatbuf.txt", "rb");
        if (!file)
        {
                printf("Failed to open file\n");
                return 1;
        }

        floatbuf = malloc(sizeof(float) * 42);
        if (fread(floatbuf, sizeof(float), 42, file) != 42)
        {
                printf("Failed to read data\n");
                fclose(file);
                free(floatbuf);
                return 1;
        }

        for (int i = 0; i < 42; i++)
                printf("%f\n", (double)floatbuf[i]);

        fclose(file);
        free(floatbuf);

        return 0;
}

=== code end ===

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to