C programming help
andrew clarke
mail at ozzmosis.com
Sun Apr 18 19:09:20 UTC 2010
On Sun 2010-04-18 14:29:16 UTC+0200, Ugur Arpaci (ugurarpaci at gmail.com) wrote:
> I am working on a project by using C programming language, but i stuck
> somewhere and i need help.
> I am reading strings from a file, and i need to make some changes from one
> of these string and then i will write this string back to the file.
> The problem is; i must make those changing on Terminal by moving cursor
> left and right by arrow keys.
> (There will be string, i make changes on it, when i press ENTER, i pass
> this string modification part)
> any idea?
> Thanks.
Here's some example C code for readline, with initial startup text
'Hello world.' that can be edited by the user.
/*
* Tested under Ubuntu 9.10 and FreeBSD 7.3.
*
* In Ubuntu you should install the readline development files:
*
* sudo apt-get install libreadline-dev
*
* Build with:
*
* cc -W -Wall -o blah blah.c -lreadline
*/
#include <stdio.h>
#include <stdlib.h>
#include <readline/readline.h>
static int rl_startup(void)
{
char startup_line[] = "Hello world.";
return rl_insert_text(startup_line);
}
int main(void)
{
char *p;
rl_startup_hook = (Function*) rl_startup;
p = readline(NULL);
printf("`%s`\n", p);
free(p);
return 0;
}
Regards
Andrew
More information about the ubuntu-users
mailing list