HOW CAN I USE "ftell" ????
Hi everybody,
I wanna know the end position of a file. So I write this routine: #include "udf.h" DEFINE_ON_DEMAND(example) { FILE *fp; long len; fp=fopen("moment.txt","rb"); if(fp == NULL) printf("ERROR!!!!"); len=ftell(fp); /*get position at end (length)*/ fclose(fp); } Fluent report: error: ftell : undeclared variable. WHY ?!?! CAN ANYBODY HELP ME?! thanks. |
If you add
#include <stdio.h> does this help? cheers |
I have to read the number in a file .txt; the file is like the following:
12.3 43.2 123.4 122.3 HOW CAN I READ THE NUMBER TILL THE END? ps. In Fluent you have to include only the file header udf.h : #include "udf.h" pps. sei italiano? |
hi enrico,
as far as i know "udf.h" will include some standard IO-functions, but not the more sophisticated ones. Try to include "std.io" and see what happens. Sorry i am not Italian, my synonym originates from an Italian girl i once knew, but something went wrong as you may perceive easily. cheers |
Quote:
The following code should do the trick: Code:
#include "udf.h" |
Thanks a lot for your reply.
Do you know how can I read only the last number on a .txt file? |
It reads the last number
:) Well, my example this is what actually does: it reads the last number from the file. It reads all of them, but only the last remains after it exits the "while" loop.
|
Oh yes! of course!!! ;)
I compile the following text on fluent, but it reports an error: #include "udf.h" DEFINE_ON_DEMAND(example) { #if !PARALLEL FILE *fp; double bubu; fp=fopen("moment.txt","r"); if(fp == NULL) Message("ERROR!!!!\n"); while(!feof(fp)) { fscanf(fp,"%lf",&bubu); } fclose(fp); #endif } Error: example.c: line 13: feof: undeclared variable I compile it as INTERPRETED. I try also as COMPILED, but it doesn't work. Do you know if I have to add some header files when I use FEOF ? An other question: what's the meaning of #if !PARALLEL ? Thank in advance. |
Hi Enrico,
The function feof() is declared in the header stdio.h, which I think is already included by udf.h, but just in case add it: Code:
#define "udf.h" Code:
#if !PARALLEL ...#endif |
Thanks a lot for your quikly replies!
IT WORKS (whitout including stdio.h ), but only as compiled! Thanks! ;) |
All times are GMT -4. The time now is 00:48. |