【发布时间】:2020-05-06 06:09:57
【问题描述】:
当我尝试在我的程序中输入float 或double 时,它给了我运行时错误“未加载浮点数”...
我正在使用 DMC 编译器
在这个程序中,我试图从用户那里获取输入,一切正常。我没有输入价格,而是在 double 类型的结构中定义了价格,程序给了我 floating point not loaded 的运行时错误。我搜索了互联网,但没有找到任何东西。
是什么导致了这个错误,我该如何解决?
这是代码:-
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node {
char isbn[16];
char title[60];
char author[40];
double price;
int issueSTATUS;
long count;
struct node *next;
};
struct node *bookdb;
void display();
void main() {
bookdb = NULL;
append();
display();
getch();
}
void append() {
struct node *temp = (struct node *) malloc(sizeof(struct node));
printf("Enter the Book ISBN : ");
scanf("%s", temp->isbn);
printf("Enter the Book Name : ");
scanf("%s", temp->title);
printf("Enter the Book Author Name : ");
scanf("%s", temp->author);
printf("Enter the Book Price : ");
scanf("%f", &temp->price); //<--------------------------here's the problem---------------------
temp->issueSTATUS = 0;
temp->next = NULL;
if(bookdb == NULL) {
bookdb = temp;
bookdb->count++;
} else {
struct node *iterator = bookdb;
while(iterator->next != NULL) {
iterator = iterator->next;
}
iterator->next = temp;
}
}
void display() {
struct node *temp = bookdb;
while(temp->next != NULL) {
printf("|%-16s|%-60s|%-20s|$%-5.2f|");
if(temp->issueSTATUS == 1) {
printf("YES\n");
} else {
printf("NO\n");
}
temp = temp->next;
}
printf("|%-16s|%-60s|%-20s|%-5.2f|");
if(temp->issueSTATUS == 1) {
printf("YES\n");
} else {
printf("NO\n");
}
}
【问题讨论】:
-
用
-Wall -Wextra编译,编译器会告诉你 -
请不要添加不相关的标签。如果您使用 C 编程,则不要添加 C++ 标签(它们是两种截然不同的语言)。并且
dmcs标签与 Mono C# 编译器的联系可能比“DMC 编译器”更紧密(无论是什么编译器,您是指 Digital Mars C 编译器吗?)。 -
如果您使用 Digital Mars C 编译器(为什么?您的目标是旧的 DOS 系统?否则它似乎非常过时)那么this reference 应该会很有帮助。查看
-f、-fd和-ff开关。 -
请使用复制和粘贴将文本输出作为文本添加到问题中。无需显示几乎是空白屏幕的图形。
-
我不知道你的编译器。但是一些编译器提供了不同版本的 C 标准库,支持或不支持浮点类型。看来您的程序是使用如此小的有限库构建的。您应该查阅编译器手册以检查正确的设置。
标签: c floating-point runtime-error scanf