Ошибка "floating formats are not linked" - C (СИ)
Формулировка задачи:
Доброго дня.
Вот такой код:
При исполнении вот этого куска кода проблема:
Ввожу номер поезда, жму enter и программа аварийно звершает работу с ошибкой floating formats are not linked. то есть с dep_time какой-то косяк. Если выставлять им тип int, то все ок. как лечить?
Компилятор Borland C++ 2.0
Спасибо.
#include <stdio.h> #include <conio.h> #include <io.h> #include <malloc.h> #include <string.h> struct Trains { char station_name[20]; int train_number; float dep_time; float road_time; Trains *next; }; struct sched { Trains *begin; }; void menu(); void create(sched *&); void read(sched *); sched *index=NULL; main() { menu(); getch(); return 0; } void menu() { char quit; enum{false,true}; quit = false; while(true) { int choice; printf("\n 1 - new sched"); printf("\n 2 - read sched"); printf("\n 0 - exit \n"); scanf("%d", &choice); switch (choice) { case (1): create(index); break; case (2): read(index); break; case (0): quit = true; } if (quit == true) break; } } void create(sched *&index) { index->begin = NULL; Trains *p,*pred=NULL; do { p = (Trains *)malloc(sizeof(Trains)); printf("Add station name: "); scanf("%s", &p->station_name); printf("Add train number: "); scanf("%d", &p->train_number); printf("Add departure time: "); scanf("%f", &p->dep_time); printf("Add road time: "); scanf("%f", &p->road_time); if (index->begin==NULL) index->begin = p; else pred->next=p; pred=p; puts("\n Finish - <esc>"); } while (getch()!=27); p->next = NULL; c++; } void read(sched *index) { Trains *headTrains = index->begin; while (headTrains) { printf("\n Station name: %s Train number: %d Departure time: %f Road time: %f",headTrains->station_name,headTrains->train_number,headTrains->dep_time,headTrains->road_time); headTrains = headTrains->next; } }
printf("Add train number: "); scanf("%d", &p->train_number); printf("Add departure time: "); scanf("%f", &p->dep_time);
Решение задачи: «Ошибка "floating formats are not linked"»
textual
Листинг программы
#include <stdio.h> #include <stdlib.h> struct Node { int iVal; float fVal; Node * next; }; #define NUM_NODES 3 int main(void){ Node * top, * last, * cur; int i; top = NULL; for ( i = 0; i < NUM_NODES; ++i ){ if ( ( cur = (Node*)malloc(sizeof(Node)) ) == NULL ){ perror("malloc"); return (1); } printf("Node #%d:\n", i + 1); printf("Integer value: "); scanf("%d", &cur->iVal); printf("Floating value: "); scanf("%f", &cur->fVal); cur->next = NULL; if ( ! top ) top = cur; else last->next = cur; last = cur; } printf("INT VAL FLOATING VAL\n"); for ( last = top; last; last = last->next ) printf("%d\t%f\n", last->iVal, last->fVal); while ( top ){ last = top->next; free(top); top = last; } system("pause"); return (0); }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д