DMC 编译器 - C 中的 "Floating point not loaded" 错误
DMC compiler - "Floating point not loaded" error in C
当我试图在我的程序中输入 float
或 double
类型时,它给我运行时错误 "Floating point is not loaded"。 ..
我正在使用 DMC 编译器
在这个程序中,我试图从用户那里获取输入,一切正常。我没有输入价格,而是在 double 类型的结构中定义了价格,程序给出了 未加载浮点数 的运行时错误。我搜索了互联网,但没有找到任何东西。
导致此错误的原因是什么,我该如何解决?
这是错误屏幕:
这是代码:-
#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");
}
}
首先,检查您的 DMC 版本是否启用了浮点类型的使用。根据文档,这很有可能会导致问题:
Floating point not loaded
The program attempts to perform floating point operations, but the floating point run-time system is not linked. Run OBJ2ASM on the object file to ensure that the external reference _fltused was generated. Otherwise, remove the floating point operation.
其次,如果启用浮点类型,考虑:
scanf("%f", &temp->price);
scanf()
中的 %f
格式说明符需要 * float
类型的参数,但 &temp->price
是 *double
.
类型的参数
使用 %lf
代替 double
:
scanf("%lf", &temp->price);
旁注:
display()
中的printf("|%-16s|%-60s|%-20s|%-5.2f|");
的目的是什么?格式化字符串攻击? printf
的这种用法是不正确的。每个格式说明符都需要有一个适当的对应参数。
main
的 return 类型应为 int
,而不是 void
。
考虑更新到更新的编译器,例如 f.e。在 Windows.
上使用 MingW-w64 的 GCC
当我试图在我的程序中输入 float
或 double
类型时,它给我运行时错误 "Floating point is not loaded"。 ..
我正在使用 DMC 编译器
在这个程序中,我试图从用户那里获取输入,一切正常。我没有输入价格,而是在 double 类型的结构中定义了价格,程序给出了 未加载浮点数 的运行时错误。我搜索了互联网,但没有找到任何东西。
导致此错误的原因是什么,我该如何解决?
这是错误屏幕:
这是代码:-
#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");
}
}
首先,检查您的 DMC 版本是否启用了浮点类型的使用。根据文档,这很有可能会导致问题:
Floating point not loaded
The program attempts to perform floating point operations, but the floating point run-time system is not linked. Run OBJ2ASM on the object file to ensure that the external reference _fltused was generated. Otherwise, remove the floating point operation.
其次,如果启用浮点类型,考虑:
scanf("%f", &temp->price);
scanf()
中的 %f
格式说明符需要 * float
类型的参数,但 &temp->price
是 *double
.
使用 %lf
代替 double
:
scanf("%lf", &temp->price);
旁注:
display()
中的printf("|%-16s|%-60s|%-20s|%-5.2f|");
的目的是什么?格式化字符串攻击?printf
的这种用法是不正确的。每个格式说明符都需要有一个适当的对应参数。main
的 return 类型应为int
,而不是void
。考虑更新到更新的编译器,例如 f.e。在 Windows.
上使用 MingW-w64 的 GCC