【发布时间】:2017-08-27 03:12:16
【问题描述】:
我试图在链表中插入文件的元素,我使用了两个函数,一个加载和插入,函数加载显然以正确的方式运行,但是函数插入正在启动实现并没有结束,测试我注意到她设法输入了文件的前 3 行,但没有正确完成插入,因为代码很长,所以它的一部分有问题:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define RECS_PATIO 2
struct Rec_Emp {
char nome_rec[10];
int uso_rec;
int taxa_rec;
/* struct Rec_Emp *prox; */
};
typedef struct Rec_Emp recuperadora;
struct Patio {
char iden_patio;
int capacidade;
struct Patio *prox;
struct Rec_Emp *lista[RECS_PATIO];
};
typedef struct Patio patio;
void insere_patio (patio *cabeca, patio *novo) {
patio *p = cabeca;
while (p->prox != NULL)
p = p->prox;
novo->prox = p->prox;
p->prox = novo;
}
void carrega_patio (patio *pa, patio p, recuperadora r1, recuperadora r2) {
patio *pt = pa;
FILE *f;
f = fopen ("portorec.txt", "rt");
if (f == NULL) {
printf ("Problema na abertura do arquivo");
return;
}
while (!feof(f)) {
fscanf (f, "%d %c %s %s %d %d %d %d", &p.capacidade, &p.iden_patio, r1.nome_rec, r2.nome_rec, &r1.uso_rec, &r2.uso_rec, &r1.taxa_rec, &r2.taxa_rec);
p.lista[0] = &r1;
p.lista[1] = &r2;
insere_patio(pt, &p);
}
fclose(f);
}
int main {
patio *PT;
PT = malloc(sizeof(patio));
PT->prox = NULL;
patio pat;
recuperadora rec1, rec2;
carrega_patio(PT, pat, rec1, rec2);
}
文件
600000 A REC01 - 0 -1 6000 -1
600000 B REC01 REC03 0 0 6000 8000
600000 C REC02 REC03 0 0 6000 8000
600000 D REC02 - 0 -1 6000 -1
2400000 E ER01 ER02 0 0 8000 8000
2400000 F REC04 ER01 0 0 8000 8000
2400000 G REC04 - 0 -1 8000 -1
2400000 H REC05 - 0 -1 8000 -1
2400000 I REC05 - 0 -1 8000 -1
2400000 J ER02 - 0 -1 8000 -1
【问题讨论】:
标签: c file linked-list