c - xcode 和 Dev-C++ 的不同行为

标签 c xcode3.2

刚开始学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;
 }

最佳答案

我猜它与 system("PAUSE"); 语句有关。 Xcode 在 OSX 上使用,它是 UNIX 的变体,没有命令 pause

为什么不让用户手动按下回车键呢?像这样:

printf("Press the ENTER key to continue.\n");
int c;
do
{
    c = fgetc(stdin);
} while (c != '\n' && c != EOF);

它具有适用于大多数系统的优势。

关于c - xcode 和 Dev-C++ 的不同行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9080610/

相关文章:

c - 如何在Xcode中编译包含多个文件的C程序

c - GCC、ARMboot - 创建没有任何库和任何操作系统的独立应用程序

c - 在 if 语句之外保留并打印值

c++ - char** vs char* c[] 用于访问字符串数组

c++ - 是否有任何 sqlite API (C API) 替代 BEGIN TRANSACTION 和 COMMIT

iphone - 是否可以使用 XCode 3.2.3 中的 iPhone Simulator 3.1?

ios - 播放视频时如何重置 MPMoviePlayerController 的内容 URL?

itunes - ipa 在 iTunes 11 中安装失败

c - argv 字符串上的 malloc 错误

iphone - Cocos2d安装