【发布时间】:2012-01-31 13:50:31
【问题描述】:
刚开始学习 C。
如果我在 Dev-C++ 中编译以下代码,程序运行良好。
如果我在 Xcode 3.2.6 中编译,它看起来像在屏幕截图中。
我在 Xcode 中尝试了不同的编译器设置,但行为仍然相同。
对此有何想法?
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char artist[30];
char album[30];
int tracks;
char albumsingle;
float price;
printf("Please enter CD informations below. \n \n");
printf("enter cd artist: ");
scanf("%[^\n]", artist);
printf("enter cd title: ");
fflush(stdin);
scanf("%[^\n]", album);
printf("enter no. of tracks: ");
fflush(stdin);
scanf("%d", &tracks);
printf("enter a for album s for single: ");
fflush(stdin);
scanf("%c", &albumsingle);
printf("enter price: ");
fflush(stdin);
scanf("%f", &price);
printf("\n\n\nartist: %s\n", artist);
printf("album: %s\n", album);
printf("track no.: %d\n", tracks);
if (albumsingle == 'a'){
printf("cd type: album\n");
} else {
printf("cd type: single\n");
}
printf("price: %.2f EUR\n\n", price);
system("PAUSE");
return 0;
}
【问题讨论】:
-
什么截图?无需添加屏幕截图,只需在您的问题或预期输出和实际输出中添加错误消息即可。