In article <11**********************@v3g2000hsg.googlegroups. com>,
Joakim Hove <jo*********@gmail.comwrote on Monday 12 Nov 2007 8:55
pm:
[I am sorry if this post is a contradiction in terms - i.e. if there
is no such thing as stdio in the C standard?]
Standard C does specify I/O functions collected under a header called
stdio.h.
I am reading a filename from the user - the loop is typically like
this:
1. Read a directory from the user.
Standard C has no support for directories. But POSIX has standardised
functions for accessing directories.
2. Read several filenames from the user.
The filenames read in 2. above will typically (but not necessarily) be
located in the directory entered under point 1., so to make it more
streamlined for the user I would like something like
Give name of file with.. =/some/path/given/first/_
I.e. the path /some/path/given/first/ should be printed first, and
then user can continue editing. I have the following two requirements:
If I understand you correctly, you want to print out the path and then
let the user type the filename just after it and also edit the path
string if they so desire.
Standard C has no support for command line editing. This is usually
provided by your operating system's terminal code. Alternatively you
might consider the reasonably portable curses library. Versions exist
for most major systems.
1. When the user has completed the input buffer should contain the
full path to some file. [This I can manage by initalising the input
buffer.]
Just print out the path name and tell the user to enter the filename on
the following line. If they want to specify another path then they can
enter a full pathname instead of just a filename. You can then read in
the line and if a directory separator is present then you know that a
new path has been specified. Otherwise you can just concatenate your
preselected path with the filename input.
This method is portable and is not of much inconvenience to users.
2. If some file is located in another location, the user should be
able to delete parts of the path, so the final result can be .e.g. /
some/other/path/file.txt
Standard C does not guarantee this. Your system might however provide
this capability, but you'll likely have to use low-level terminal
functions.
I have looked into gnu readline - but it does not seem it provides
this functionality. Any tips gretly appreciated.
IMO losing portability for a small cosmetic UI feature is not worth it.
However YMMV. For more details post to a system specific group like
<news:comp.unix.programmeror
<news:comp.os.ms-windows.programmer.win32>.