鱼C论坛

 找回密码
 立即注册
查看: 1948|回复: 4

[已解决]为什么有的语句不执行了?

[复制链接]
发表于 2021-2-12 19:11:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include <stdio.h>

struct Date
{
        int year;
        int month;
        int day;
};

struct Book
{
        char title[128];
        char auther[40];
        float price;
        struct Date date;
        char publissher[40];
};

//录入书本信息
void *getInput(struct Book *book)
{
        printf("请输入书名:");
        scanf("%s",book->title);
        printf("请输入作者:");
        scanf("%s",book->auther);
        printf("请输入售价:");
        scanf("%f",book->price);
//----------------------这里以下的语句都不执行了------------------------------------------//请教大佬,拜托了[手动鞠躬]
        printf("请输入出版日期:");
        scanf("%d %d %d",(*book).date.year,(*book).date.month,book->date.day);
        printf("请输入出版社:");
        scanf("%s",book->publissher);
       

}

//打印输入结果
void *printBook(struct Book *book )
{
        printf("书名:%s\n",book->title);
        printf("作者:%s",(*book).auther);
        printf("出版日期:%d-%d-%d\n",(*book).date.year,(*book).date.month,(*book).date.day);
        printf("售价:%.2f\n",(*book).price);
        printf("出版社:%s\n",(*book).publissher);
       

}

int main(void)
{
        struct Book b1, b2;
       
       
        printf("请输入第一本书的信息;\n");
         getInput(&b1);
        putchar('\n');
       
        printf("请输入第二本书的信息");
       
         getInput(&b2);
       
        printf("\n===================================");
       
        printf("\n录入完毕,打印第一本书的信息\n");
        printBook(&b1);
       
        printf("第二本书的信息:\n");
        printBook(&b2);
       
        return 0;
}
最佳答案
2021-2-12 19:34:24
改成这样:

  1. #include <stdio.h>

  2. struct Date
  3. {
  4.         int year;
  5.         int month;
  6.         int day;
  7. };

  8. struct Book
  9. {
  10.         char title[128];
  11.         char auther[40];
  12.         float price;
  13.         struct Date date;
  14.         char publissher[40];
  15. };

  16. //录入书本信息
  17. void *getInput(struct Book *book)
  18. {
  19.         printf("请输入书名:");
  20.         scanf("%s",book->title);
  21.         printf("请输入作者:");
  22.         scanf("%s",book->auther);
  23.         printf("请输入售价:");
  24.         scanf("%f",&book->price);
  25. //----------------------这里以下的语句都不执行了------------------------------------------//请教大佬,拜托了[手动鞠躬]
  26.         printf("请输入出版日期:");
  27.         scanf("%d %d %d",&(*book).date.year,&(*book).date.month,&book->date.day);
  28.         printf("请输入出版社:");
  29.         scanf("%s",book->publissher);
  30.       

  31. }

  32. //打印输入结果
  33. void *printBook(struct Book *book )
  34. {
  35.         printf("书名:%s\n",book->title);
  36.         printf("作者:%s\n",(*book).auther);
  37.         printf("出版日期:%d-%d-%d\n",(*book).date.year,(*book).date.month,(*book).date.day);
  38.         printf("售价:%.2f\n",(*book).price);
  39.         printf("出版社:%s\n",(*book).publissher);
  40.       

  41. }

  42. int main(void)
  43. {
  44.         struct Book b1, b2;
  45.       
  46.       
  47.         printf("请输入第一本书的信息;\n");
  48.         getInput(&b1);
  49.         putchar('\n');
  50.       
  51.         printf("请输入第二本书的信息\n");
  52.       
  53.         getInput(&b2);
  54.       
  55.         printf("\n===================================");
  56.       
  57.         printf("\n录入完毕,打印第一本书的信息\n");
  58.         printBook(&b1);
  59.       
  60.         printf("第二本书的信息:\n");
  61.         printBook(&b2);
  62.       
  63.         return 0;
  64. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-2-12 19:33:30 | 显示全部楼层
你是不是输入作者或者书名的时候里面有空格

评分

参与人数 1鱼币 +1 收起 理由
qiuyouzhi + 1 和那个没关系,就是scanf用法问题

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-2-12 19:34:24 | 显示全部楼层    本楼为最佳答案   
改成这样:

  1. #include <stdio.h>

  2. struct Date
  3. {
  4.         int year;
  5.         int month;
  6.         int day;
  7. };

  8. struct Book
  9. {
  10.         char title[128];
  11.         char auther[40];
  12.         float price;
  13.         struct Date date;
  14.         char publissher[40];
  15. };

  16. //录入书本信息
  17. void *getInput(struct Book *book)
  18. {
  19.         printf("请输入书名:");
  20.         scanf("%s",book->title);
  21.         printf("请输入作者:");
  22.         scanf("%s",book->auther);
  23.         printf("请输入售价:");
  24.         scanf("%f",&book->price);
  25. //----------------------这里以下的语句都不执行了------------------------------------------//请教大佬,拜托了[手动鞠躬]
  26.         printf("请输入出版日期:");
  27.         scanf("%d %d %d",&(*book).date.year,&(*book).date.month,&book->date.day);
  28.         printf("请输入出版社:");
  29.         scanf("%s",book->publissher);
  30.       

  31. }

  32. //打印输入结果
  33. void *printBook(struct Book *book )
  34. {
  35.         printf("书名:%s\n",book->title);
  36.         printf("作者:%s\n",(*book).auther);
  37.         printf("出版日期:%d-%d-%d\n",(*book).date.year,(*book).date.month,(*book).date.day);
  38.         printf("售价:%.2f\n",(*book).price);
  39.         printf("出版社:%s\n",(*book).publissher);
  40.       

  41. }

  42. int main(void)
  43. {
  44.         struct Book b1, b2;
  45.       
  46.       
  47.         printf("请输入第一本书的信息;\n");
  48.         getInput(&b1);
  49.         putchar('\n');
  50.       
  51.         printf("请输入第二本书的信息\n");
  52.       
  53.         getInput(&b2);
  54.       
  55.         printf("\n===================================");
  56.       
  57.         printf("\n录入完毕,打印第一本书的信息\n");
  58.         printBook(&b1);
  59.       
  60.         printf("第二本书的信息:\n");
  61.         printBook(&b2);
  62.       
  63.         return 0;
  64. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-2-13 00:05:06 | 显示全部楼层

不是,小甲鱼的源代码似乎就是那么写的,我前两天刚看到这里

我当时就是输入了一个空格在中间,就直接跨过了下一个输入
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-2-13 00:07:03 | 显示全部楼层
本帖最后由 Daniel_Zhang 于 2021-2-13 00:09 编辑


你看,直接就跳过了,我复制粘贴你的代码

截屏2021-02-13 00.05.35.png

输入了 q q

然后回车

直接让我输入售价了

最后的结果: 第二个 q 直接窜到了作者那里

截屏2021-02-13 00.08.26.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-19 19:21

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表