代码之家  ›  专栏  ›  技术社区  ›  user5721274

windows的正确ansi c示例是什么?[已关闭]

  •  1
  • user5721274  · 技术社区  · 9 年前

    一些书声称他们使用了ansi c并使用了turbo c编译器来运行这些示例。我试图在linux上运行这些,但我发现这些示例只适用于windows。

    #include<stdio.h>
    #include<conio.h>
    /* #include<dos.h> */
    int main()
    {
        int a;
        clrscr();
        scanf("%d", &a);
        printf("%d",a);
        getch();
        return 0;
    }
    

    我可以把上面的例子称为ansi-c吗?为什么或为什么不?

    2 回复  |  直到 9 年前
        1
  •  0
  •   cdonts    9 年前

    正如@milevyo所说,这些函数由Borland的编译器实现。在Windows上,您可以替换 clrscr() 具有 system("cls") getch(); 具有 _getch(); 或者甚至更好, getchar() .

        2
  •  0
  •   Sneha    9 年前

    conio.h 文件目录仅受支持 Borland C 。您可以使用 getchar() 而不是 getch() .

    如果您必须使用 获取() 无论如何,你可以使用 curses.h 文件而不是 圆锥形.h 。它提供了 圆锥形.h 具有 获取() .

    如果你没有得到 诅咒.h 目录已安装,然后您可以从 here

    #include <stdio.h>
    #include <ncurses.h>
    
    int main()
    {
        initscr();              /* start the curses mode */
        int a;
        scanf("%d", &a);
        printf("%d",a);
    
        getch();
        endwin();
    
     return 0;
    }