Click to See Complete Forum and Search --> : "raw_input()" in C?


hop-frog
10-15-2003, 07:00 PM
In Python a prompt can be made using:raw_input(">")Is there a commonly used equivalent to this in ANSI C that is used for a similar command prompt? I have a program that uses a colon for a command prompt. I just need to change this to a carrot ">" so that it is actually recognizable as a command prompt. I ran grep in search of all colons (including "\058" and "3A") present in the source, but AFAICT none of them had anything to do with the one used for a prompt.

sploo22
10-15-2003, 07:20 PM
How about this:

/* Declare variable to hold string */
char stringbuf[100];

printf(">");
fgets(stringbuf, 100, stdin);
stringbuf[strlen(stringbuf)-1] = '\0';


That last line is to get rid of the trailing newline character that fgets leaves on.

Hope this is what you're looking for! :)

hop-frog
10-15-2003, 07:45 PM
Thanks!