C-使用printf时的行限制
现在的问题是:magazzino.dat中有很多产品,所以当我运行它时,我超出了我可以打印的行数限制,所以它切断了一些产品。我怎样才能解决这个问题?我知道这里和那里可能会有一些错误,但这不是重点,我仍然需要修复一些东西。我现在唯一的问题就是这个 也许我还有一个疑问,那就是列表传递函数中的feoffile条件。这样写对了吗 虽然菲菲{ 因为我得到了两个产品,在打印函数的末尾,所有字段都设置为零C-使用printf时的行限制,c,printf,lines,C,Printf,Lines,现在的问题是:magazzino.dat中有很多产品,所以当我运行它时,我超出了我可以打印的行数限制,所以它切断了一些产品。我怎样才能解决这个问题?我知道这里和那里可能会有一些错误,但这不是重点,我仍然需要修复一些东西。我现在唯一的问题就是这个 也许我还有一个疑问,那就是列表传递函数中的feoffile条件。这样写对了吗 虽然菲菲{ 因为我得到了两个产品,在打印函数的末尾,所有字段都设置为零 非常感谢!如果这真的是一个控制台限制,那么执行您的文件并将其传送到更多控制台如何,即尝试记住DOS术语:
非常感谢!如果这真的是一个控制台限制,那么执行您的文件并将其传送到更多控制台如何,即尝试记住DOS术语:
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");
}
我超出了可以打印的行数限制?你是说它们比控制台中可打印的行数多?你不能在之后向上滚动控制台窗口吗?有关feof问题,请查看哪个控制台?cmd?IDE的控制台?你可以增加控制台缓冲区大小。如果控制台是cmd.exe,请右键单击标题栏,然后单击“属性”。
\path\to\program arg1 arg2 | more