欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 關于C語言結構體顯示的問題 [打印本頁]

作者: laopihappy123    時間: 2020-10-22 22:07
標題: 關于C語言結構體顯示的問題
想把結構體用在單片機上 可是發現我不會,我就用turboc寫了個試試
結果根本沒有用 搞得焦頭爛額 希望大家幫幫我
如圖 綠色熒光筆為我想顯示的代碼,結果顯示null 我暈倒!

屏幕截圖 2020-10-22 220403.png (6.08 KB, 下載次數: 102)

屏幕截圖 2020-10-22 220403.png

屏幕截圖 2020-10-22 220244.png (53.04 KB, 下載次數: 80)

屏幕截圖 2020-10-22 220244.png

作者: my808    時間: 2020-10-22 22:07
我猜樓主是想實現以下功能:

用循環來輸入書本的信息,但是預先不知道要輸入多少本,當answer  == 1 時就停止輸入,
然后打印書本的總數,并且輸出每一本的信息。


若真是這樣,難度有點大……
作者: jtfa    時間: 2020-10-23 06:54
你連數組操作這塊都還沒搞清楚。
作者: i_could_have    時間: 2020-10-24 14:47
  1. #define _CRT_SECURE_NO_WARNINGS

  2. #include <stdio.h>
  3. struct books{
  4.     char name[20];
  5.     char author[20];
  6.     float price[20];
  7. };
  8. int i = 1;
  9. int main(void)
  10. {
  11.     struct books library;
  12.     printf("name of the book?\n");
  13.     scanf_s("%s", library.name,20);
  14.     printf("author of the book?\n");
  15.     scanf_s("%s", library.author,20);
  16.     printf("price of the book?\n");
  17.     scanf("%f", &library.price[i-1]);
  18.     int answer = 0;
  19.     if (scanf("%d", &answer) == 1)
  20.     {
  21.         printf("You got %d books\n", i);
  22.         for (; i > 0; i--)
  23.         {
  24.             printf("book number:%d\n", i);
  25.             printf("name:%s\n", library.name);
  26.             printf("author:%s\n", library.author);
  27.             printf("price:%f\n", library.price[i-1]);
  28.         }
  29.         return 0;
  30.     }
  31.     else i++;
  32.     return 1;
  33. }
  34. 字符數組不用&,字符數組的名字就代表的是首地址
復制代碼

作者: i_could_have    時間: 2020-10-24 15:27
本帖最后由 i_could_have 于 2020-10-24 15:39 編輯
  1. #define _CRT_SECURE_NO_WARNINGS

  2. #include <stdio.h>
  3. struct books{
  4.     char name[20];
  5.     char author[20];
  6.     float price[20];
  7. };
  8. int i = 1;
  9. int main(void)
  10. {
  11.     struct books library;
  12.     printf("name of the book?\n");
  13.     scanf_s("%s", library.name,20);
  14.     printf("author of the book?\n");
  15.     scanf_s("%s", library.author,20);
  16.     printf("price of the book?\n");
  17.     scanf("%f", &library.price[i-1]);
  18.     int answer = 0;
  19.     if (scanf("%d", &answer) == 1)
  20.     {
  21.         printf("You got %d books\n", i);
  22.         for (; i > 0; i--)
  23.         {
  24.             printf("book number:%d\n", i);
  25.             printf("name:%s\n", library.name);
  26.             printf("author:%s\n", library.author);
  27.             printf("price:%f\n", library.price[i-1]);
  28.         }
  29.         return 0;
  30.     }
  31.     else i++;
  32.     return 1;
  33. }

  34. 你把字符數組鍵盤輸入那塊的&符號去掉。
復制代碼





歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1