我有练习题。我应该读取包含两个结构的写入文件,当从文件中读取#
字符时,产品的第二个结构应该停止读取,然后在结构之前开始读取,然后存储产品。你可以帮我吗?从带有特殊字符的文件中读取链接列表#
我无法从结构文件读取数据,然后将其停止为#字符。 我想我需要两个while第一个法则struct elements的元素,以及那些struct product的第二个法则,并且停止在字符#处。
有没有人可以这样写代码?
与在单独的行的每个项目的文件中,仅结构产品的线是在同一行上:
(Cod_p名称量)
整个仅分离空间。
文件的组织结构如下:
ENG0002
高街,8
伦敦
英格兰
SCG8888短裤200
FFSF888衬衫200
#
TRA456456
公园路,88
伦敦
英格兰
ASDASD000短裤100
ADWC000衬衫1000
YUAYO鞋122
#
#include <stdio.h>
#include <stdlib.h>
struct magazine {
char cod_m[30];
char adress[30];
char city[30];
char nation[30];
struct product* p;
struct magazine* next;
``
};
struct product {
char cod_p[10];
char name[20];
int quantity;
struct product* next;
};
void read_st(struct magazzino* m);
int main() {
struct magazzino* mag;
read_st(mag);
}
void read_st(struct magazzino* m) {
FILE* fp;
fp = fopen("magazzino.txt", "r");
while (!feof(fp)) {
struct magazzino* m = (struct magazzino*)malloc(sizeof(struct magazzino));
fscanf(fp, "%s\n%s\n%s\n%s\n", &m->cod_m, &m->adress, &m->city, &m->nation);
m->next;
printf("%s\n%s\n%s\n%s\n", &m->cod_m, &m->adress, &m->city, &m->nation);
}
}
struct prodotto* LeggiProdotto(char filename) {
FILE* fp = fopen("magazzino.txt", "r");
while (!feof(fp)) {
struct prodotto* p = (struct prodotto*)malloc(sizeof(struct prodotto));
}
}
提示:行'm-> next;'什么都不做。并阅读[this](http://stackoverflow.com/questions/5431941/why-is-while-feof-file-always-wrong)。而'LeggiProdotto'函数没有任何用处,但是你不会调用它。而且你不会'fclose'你打开的文件。可能有更多的问题。 –
哦,是的,你忘了提到你实际上有哪些问题。 –
我无法从文件中读取结构,然后将其停止到字符# – ilbranco