Ibrahim F Haddad wrote:
> as easy as it may seem (!) it is not working with me
> I have a file 'value' that contains a float of the form 1.23464
> I need to read it and store it in a variable of type float called norme.
>
> it did not work!
> So i read it as string and now i need to convert the string back to float
> as in:
> filePtr = fopen ("value", "r");
>
> if ( filePtr == NULL)
> {
> printf ("Not found!\n");
> }
> else
> {
> fscanf (filePtr, "%s", polynorme);
> printf (" Got it a string %s\n", polynorme);
> fclose (filePtr);
> }
> Up till here it worked.
>
> but,
> norme = (float) polynorme;
> printf (" Got it as float !! %d \n", norme);
>
> castind did not work.
Of course it doesn't. A cast doesn't convert the data; it just tells
the compiler to treat it differently.
To convert from a string to a float use atof().
PS: I think that you need to get a book which explains C. Your message
indicates a fundamental misunderstanding about the way that C works.
--
Glynn Clements <[EMAIL PROTECTED]>