How do I read in a long double in C?
+2
A:
Either hrnt's answer (scanf("%Lf", &x)
) or
long double x;
if(read(fd,&x,sizeof(x))!=sizeof(x)) printf("Oops\n");
the question is very vague.
Michael Krelin - hacker
2009-10-07 07:41:28
If it's C, and not necessarily on Unix, wouldn't fread be better?
Thomas Padron-McCarthy
2009-10-07 07:56:26
I think read() is equally portable. I doubt there's any difference unless you use fscanf on the same file.
Michael Krelin - hacker
2009-10-07 08:04:54
hacker: fread is in the C standard. read is not.
Thomas Padron-McCarthy
2009-10-11 13:45:31
Thomas, I was talking about de facto portability, not standards. For what I can tell by the question, OP doesn't care much about either.
Michael Krelin - hacker
2009-10-11 14:25:10
hacker: Are you saying that read and file descriptors, as shown in your example code above, will work on Windows?
Thomas Padron-McCarthy
2009-10-13 08:43:29
Thomas, last time I checked (over 10 years ago, I'm afraid) it worked on Windows.
Michael Krelin - hacker
2009-10-13 09:48:18
hacker: Ok, in that case I have no complaint. (But hey, it doesn't work on TOPS-20!)
Thomas Padron-McCarthy
2009-10-13 14:53:06
+2
A:
Be aware that "long double" is a synonym for "double" on Visual Studio.
http://blogs.msdn.com/ericflee/archive/2004/06/10/152852.aspx
RED SOFT ADAIR
2009-10-07 07:47:57
A:
you can use the format specifier %ld for reading long double variables.
Sachin Chourasiya
2009-10-07 08:25:22