gpt4 book ai didi

c - printf ("\n")\n 在我的代码 VS2013 中的任何地方随机停止工作

转载 作者:行者123 更新时间:2023-11-30 17:11:30 25 4
gpt4 key购买 nike

//testing some structs
#include <stdio.h>

struct books {
char title[50];
char author[50];
char subject[100];
int book_id;
} book;

//Function Declairations
int print_book(struct books book);

int main() {
struct books book1;
struct books book2;

strcpy(book1.title, "Spot goes to the beach");
strcpy(book1.author, "Mr Biggles");
strcpy(book1.subject, "A story of a stupid little dog that goes to the beach and chases birds.");
book1.book_id = 684687654;

strcpy(book2.title, "The Cat in the Hat");
strcpy(book2.author, "Dr Seuse");
strcpy(book2.subject, "A mischeviouse cat come to visit and causes such a mess");
book2.book_id = 5754454;

printf("Available books for hire from the library\n");

print_book(book1);
print_book(book2);
}

int print_book(struct books book) {
//prints the details of a books struct parsed as a parameter
printf("\nBook Title: %s", book.title);
printf("\nBook Author: %s", book.author);
printf("\nBook Subject: %s", book.subject);
printf("\nBook ID: %d", book.book_id);
printf("\n");
}

嘿伙计们,由于某种原因\n随机停止工作。我决定在底部添加另一个 \n 只是为了将输出与最后控制台窗口中的“按任意键继续...”分开,但它现在不起作用。

我什至尝试过转到第 28 行并插入更多 \n 例如...

printf("Available b\n\n\n\n\n\n\nooks for hire from the library\n");

输出没有差异。

最佳答案

  1. int print_book(struct books book);void print_books(...)

    您没有从该函数返回任何内容

  2. 您没有包含 string.h,因此编译器不知道 strcpy() 的声明,并假设它返回int并通过默认提升获取任意数量的参数。所以你的代码会调用未定义的行为。它可能会在这次运行,但不会在其他时间或在其他系统上运行。参见

关于c - printf ("\n")\n 在我的代码 VS2013 中的任何地方随机停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32177336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com