[英]C - Lines limit when using printf's
typedef struct product_temp{
int code;
char name[MAX_NAME];
char category[MAX_CATEGORY];
char provenience[MAX_PROVENIENCE];
int quantity;
float price;
struct product_temp *next;
} product;
product *list_transfer(FILE *file);
void print(product *head);
void *insert_tail(product *head, int code, char name[], char category[], char provenience[], int quantity, float price);
int search_code(int code, product *iterator);
product *remove_product(int code, product *head);
void free_heap(product *head);
void save_file(product *head, FILE *file);
int main (int argc, char *argv[]){
product *head;
FILE *file, *file_REFRESH;
int outcome;
file = fopen("magazzino.dat", "rb");
if(file != NULL){
head = list_transfer(file);
print(head);
insert_tail(head, 950, "Latta Pomodori", "FruttaVerdura", "Campania", 70, 0.90);
insert_tail(head, 1011, "Olio Bottiglia 1L", "Alimentari", "Puglia", 50, 4.50);
insert_tail(head, 1150, "Biscotti Busta 1Kg", "Alimentari", "Lombardia", 60, 1.50);
insert_tail(head, 1205, "Detersivo Piatti 0.75L", "Pulizia Casa", "Lombardia", 75, 1.10);
print(head);
head = remove_product(985, head);
head = remove_product(1015, head);
head = remove_product(1150, head);
print(head);
file_REFRESH = fopen("magazzino_aggiornato", "wb");
save_file(head, file_REFRESH);
fclose(file);
fclose(file_REFRESH);
free_heap(head);
}
else{
fprintf(stderr, "Non e' stato trovato il file magazzino.dat!\n");
exit(6);
}
return 0;
}
product *list_transfer(FILE *file){
product *head, *current;
head = malloc(sizeof(product));
if(head == NULL){
fprintf(stderr, "Impossibile allocare memoria!\n");
exit(5);
}
memset(head, 0, sizeof(product));
current = head;
rewind(file);
while(!feof(file)){
fread(¤t->code, sizeof(current->code), 1, file);
fread(¤t->name, sizeof(current->name), 1, file);
fread(¤t->category, sizeof(current->category), 1, file);
fread(¤t->provenience, sizeof(current->provenience), 1, file);
fread(¤t->quantity, sizeof(current->quantity), 1, file);
fread(¤t->price, sizeof(current->price), 1, file);
current->next = malloc(sizeof(product));
if(current->next == NULL){
fprintf(stderr, "Impossibile allocare memoria!\n");
exit(5);
}
memset(current->next, 0, sizeof(product));
current = current->next;
}
return head;
}
void print(product *head){
while(head != NULL){
fprintf(stdout, "Code:\t\t%d\n", head->code);
fprintf(stdout, "Name:\t\t%s\n", head->name);
fprintf(stdout, "Category:\t%s\n", head->category);
fprintf(stdout, "Provenience:\t%s\n", head->provenience);
fprintf(stdout, "Quantity:\t%d\n", head->quantity);
fprintf(stdout, "Price:\t\t%.2f\n\n", head->price);
head = head->next;
}
printf("\n");
}
現在的問題是:magazzino.dat中有很多產品,因此當我運行它時,我超出了可以打印的行數限制,因此它切斷了某些產品。 我該如何解決? 我知道可能到處都有錯誤,但這不是重點,我仍然必須解決一些問題。 我目前唯一的問題是那個。
也許我還有其他疑問,就是list_transfer函數中的feof(file)條件。 編寫是否正確:while(!feof(file)){因為在打印功能的末尾我得到兩個乘積,所有字段都設置為零。
非常感謝!
如果這確實是一個控制台限制,那么如何執行文件並將其通過管道傳輸到more
,即(嘗試記住DOS術語):
\path\to\program arg1 arg2 | more
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.