C programing problem where <= is interpreted as < when using GCC 11.2.0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you all so much for your prompt replies.

https://stackoverflow.com/questions/21895756/why-are-floating-point-numbers-inaccurate
was an extremely interesting read and although I am not proficient
in interpreting other bases this has been a total revelation to me.

I began thinking that there must be a way to read numbers from
a file and I found out about arrays and put together the following
code which seems to work just fine for me.

Thank you again, I never would have worked out the problem by
myself.

Bob

int main()
{
        FILE *myFile;
        myFile = fopen("n-array.txt", "r");    /* n-array.txt contains */
        float  nArray[81];            /*  the numbers increasing by 0.1 */
        int  i;                      /* from 2 to 10 which was what my for */
                                      /* loop was doing in my failed coding.  */
        if (myFile == NULL)
            {
                 printf("Error Reading File\n");
                 exit (0);
             }

         for (i = 0; i < 81; i = i + 1 )    /*  81 numbers from 0 to 80  */
             {
                  fscanf(myFile, "%f", &nArray[i] );  /* read file into array */
              }

         for (i = 0; i < 81; i = i + 1 )
              {
                   printf("%f\n", nArray[i] );
               }

          fclose(myFile);

return 0;
}




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux