私は自己学習Cで、現在ScanfとPrintfの機能を研究しています。Scanf/Printf in C ...ここで何が起こっていますか?
私は自分自身をテストする場合は、このプログラムを適応:私はscanfの機能の理解とどのように「繊細」彼らは可能を把握するため
char topping[24];
int slices;
int day, year;
float cost;
char month[10];
printf(" How much does a pizza cost in your area?\n");
printf("$");
scanf(" %f", &cost);
printf("What is your favorite one-word pizza topping?\n");
scanf(" %s",topping);
printf("How many slices of %s pizza, topping can you eat in one sitting\n",topping);
scanf(" %d", &slices);
printf(" What is today's date (enter in the following format 1-Jan-2016)\n");
scanf(" %d-%s-%d", &day, month, &year);
printf("\nWhy not treat yourself to dinner on %d-%s-%d and have %d slices of %s pizza ? It will only cost you %.2f", day, month, year,slices, topping,cost);
運動の目的です。
私のテストプログラムはここでうまくいきます...年変数の出力は例外です。
なぜ年変数の出力がばかげているのですが、どうすれば修正できますか?
ありがとうございます。
"%d-%9 [^ - ] - %d"と試してください –
デバッガを使用してコードをステップ実行して動作を確認する方法を学んでください –