在C中创建没有依赖项的gotoxy()函数

时间:2016-09-16 20:43:40

标签: c gcc portability

Turbo C在conio.h中提供了 public static String copyStreamToString (InputStream input, int estimatedSize, String charset) throws IOException { InputStreamReader reader = charset == null ? new InputStreamReader(input) : new InputStreamReader(input, charset); StringWriter writer = new StringWriter(Math.max(0, estimatedSize)); char[] buffer = new char[DEFAULT_BUFFER_SIZE]; int charsRead; while ((charsRead = reader.read(buffer)) != -1) { writer.write(buffer, 0, charsRead); } return writer.toString(); } 函数,但它不是标准函数。

我使用gcc编译器,需要gotoxy()函数。

我在网上搜索但发现只有特定于操作系统的功能或具有某种依赖性的功能,这使得它的便携性降低。

例如:Windows的gotoxy()函数使用Windows API,而Linux使用ncurses之类的函数。

我在here

中找到了一条建议

提及设置二维数组,为单元格指定值和绘图。

Screenshot

当我尝试它时,其中一个问题是在打印完一行之后没有gotoxy()函数就没有回来了。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:1)

您将始终具有依赖关系,因为控制台I / O的性质是特定于平台的。诸如ncurses之类的库的目的是抽象这样的平台依赖关系以提供通用接口。

ncurses适用于各种平台,包括Windows