readline库使用

谁说我不能喝 提交于 2019-12-06 12:18:18

本文档主要介绍readline库和其它程序之间的接口,主要有:自动补全、行编辑、历史交互命令等。

  1. 基本函数

 

  1. readline

函数原型:char *readline (const char *prompt);

在官方文档中,对readline函数的描述如下:

The function readline() prints a prompt prompt and then reads and returns a single line of text from the user. If prompt is NULL or the empty string, no prompt is displayed. The line readline returns is allocated with malloc(); the caller should free() the line when it has finished with it.

大意是readline()函数打印一个提示符,返回一个用户输入的单行文本,如果输入的是一个空字符串,没有参数显示。readline的返回结果是已经通过malloc分配了内存的,用户应该在调用了readline()函数之后使用free()释放它。

测试代码如下:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!