To install the readline library, open the terminal window and write
sudo apt-get install libreadline-dev
It will ask for your password. Enter it. Press y in the next step.
CODE:
1. #include <stdio.h> 2. #include <malloc.h> 3. #include <readline/readline.h> 4. 5. void main(void){ 6. 7. char *line; 8. 9. while( 1==1 ){ 10. line=readline("enter text>"); 11. printf("text: %s <\n",line); 12. free(line); 13. } 14. }
ERROR:
1. /tmp/cc6JYBvf.o: In function `main': 2. read_test.c:(.text+0xe): undefined reference to `readline'
SOLVE:
You need to link againts the actual library using -lreadline in gcc arguments:
gcc read_test.c -o read_test -lreadline
AIEarth是一个由众多领域内专家博主共同打造的学术平台,旨在建设一个拥抱智慧未来的学术殿堂!【平台地址:https://devpress.csdn.net/aiearth】 很高兴认识你!加入我们共同进步!