|
[Sponsors] |
November 16, 2009, 05:24 |
HOW CAN I USE "ftell" ????
|
#1 |
Senior Member
Herman
Join Date: Nov 2009
Posts: 122
Rep Power: 17 |
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. |
|
November 16, 2009, 10:18 |
|
#2 |
Senior Member
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17 |
If you add
#include <stdio.h> does this help? cheers |
|
November 16, 2009, 10:31 |
|
#3 |
Senior Member
Herman
Join Date: Nov 2009
Posts: 122
Rep Power: 17 |
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? |
|
November 16, 2009, 11:05 |
|
#4 |
Senior Member
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17 |
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 |
|
November 25, 2009, 08:27 |
|
#5 | |
Senior Member
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20 |
Quote:
The following code should do the trick: Code:
#include "udf.h" DEFINE_ON_DEMAND(example) { #if !PARALLEL FILE *fp; real bubu; fp=fopen("moment.txt","r"); if(fp == NULL) Message("ERROR!!!!\n"); while(!feof(pf)) { fscanf(pf,"%g",&bubu); } fclose(fp); #endif } |
||
November 26, 2009, 05:16 |
|
#6 |
Senior Member
Herman
Join Date: Nov 2009
Posts: 122
Rep Power: 17 |
Thanks a lot for your reply.
Do you know how can I read only the last number on a .txt file? |
|
November 26, 2009, 05:21 |
It reads the last number
|
#7 |
Senior Member
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20 |
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.
|
|
November 26, 2009, 06:01 |
|
#8 |
Senior Member
Herman
Join Date: Nov 2009
Posts: 122
Rep Power: 17 |
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. |
|
November 26, 2009, 06:15 |
|
#9 |
Senior Member
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20 |
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" #define<stdio.h> Code:
#if !PARALLEL ...#endif |
|
November 26, 2009, 06:46 |
|
#10 |
Senior Member
Herman
Join Date: Nov 2009
Posts: 122
Rep Power: 17 |
Thanks a lot for your quikly replies!
IT WORKS (whitout including stdio.h ), but only as compiled! Thanks! |
|
|
|