From: frijolithedog 1 <frijolithedog@outlook.com>
To: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: C programing problem where <= is interpreted as < when using GCC 11.2.0
Date: Sat, 23 Oct 2021 13:43:33 +0000 [thread overview]
Message-ID: <PSAPR04MB4311DC050EF73DD8584CB4A1B4819@PSAPR04MB4311.apcprd04.prod.outlook.com> (raw)
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;
}
next reply other threads:[~2021-10-23 13:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-23 13:43 frijolithedog 1 [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-10-14 15:20 frijolithedog 1
2021-10-14 15:31 ` Xi Ruoyao
2021-10-14 17:14 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=PSAPR04MB4311DC050EF73DD8584CB4A1B4819@PSAPR04MB4311.apcprd04.prod.outlook.com \
--to=frijolithedog@outlook.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).