Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 31st, 2005, 11:58 PM   #1
bivhitscar
Hobbyist Programmer
 
bivhitscar's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 126
Rep Power: 3 bivhitscar is on a distinguished road
Angry Problems reading a double into an array using scanf()

This code is supposed to read values (type double) from user input and place them in an array, using a loop. Easy? No, apparantly not, here's the code:

#include <stdio.h>

int main(void)
{
  double user[8];         //user's chosen numbers
  int i;                  //loop counter for user entered numbers

  for(i = 0; i <= 7; i++)
  {
    printf("Enter a number (%d to go): ", 8 - i);
    scanf("%lf", &user[i]);

  }

  return 0;
}


When I run this, I enter my first number and get this error:

Runtime error R6002
- floating point not loaded

Googled the error, but didn't get anything very definitive.


But if I use scanf to read the number to 'temp' then on the next line read 'temp' into user[i] - it works fine.

scanf("%lf", &temp);
user[i] = temp;


It also worked if I just added a line right after scanf, printing what the value of i and user[i] was.

scanf("%lf", &user[i]);
printf("user[%d] = %f", i, user[i]);


I can't figure out why this doesn't work.

And if anyone has issues with me using scanf(), I already know there's better options, but I'm learning from a book and I should technically be able to do this.
__________________
it's ironic considerate rarity patron of love higher knowledge engulfs me...
bivhitscar is offline   Reply With Quote
Old Nov 1st, 2005, 12:24 AM   #2
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
Works for me. gcc version 3.2.2.
Specify your OS/compiler.
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Nov 1st, 2005, 12:30 AM   #3
bivhitscar
Hobbyist Programmer
 
bivhitscar's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 126
Rep Power: 3 bivhitscar is on a distinguished road
Bah, it had to be microsoft's fault. I'm using the VC++ 2003 toolkit.
__________________
it's ironic considerate rarity patron of love higher knowledge engulfs me...
bivhitscar is offline   Reply With Quote
Old Nov 1st, 2005, 12:30 AM   #4
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
I think it was a problem with some old compilers when the floating point emulator routine wasn't loaded and one tried to use the address of floating point numbers. Not sure though.
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Nov 1st, 2005, 12:31 AM   #5
bivhitscar
Hobbyist Programmer
 
bivhitscar's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 126
Rep Power: 3 bivhitscar is on a distinguished road
Oh, on windows xp.
__________________
it's ironic considerate rarity patron of love higher knowledge engulfs me...
bivhitscar is offline   Reply With Quote
Old Nov 1st, 2005, 12:33 AM   #6
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
Try to run the executable from outside the development environment and see if the error pops up again.
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Nov 1st, 2005, 12:35 AM   #7
bivhitscar
Hobbyist Programmer
 
bivhitscar's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 126
Rep Power: 3 bivhitscar is on a distinguished road
Oh, I don't have the whole suite, I'm just using the free tools they provide. Basically it's the .net compiler/linker without the ide.
__________________
it's ironic considerate rarity patron of love higher knowledge engulfs me...
bivhitscar is offline   Reply With Quote
Old Nov 1st, 2005, 12:52 AM   #8
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
I found it here
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Nov 1st, 2005, 1:47 AM   #9
bivhitscar
Hobbyist Programmer
 
bivhitscar's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 126
Rep Power: 3 bivhitscar is on a distinguished road
So, I found out how to fix the problem on my own anyway? Go me.

Thanks for that link though, the M$ article I found listed about 7 different reasons as to why it could be happening.
__________________
it's ironic considerate rarity patron of love higher knowledge engulfs me...
bivhitscar is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:37 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC