| | |
Need help with expanding a unix path correctly.
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
User supplied file names must be either absolute or relative to the application. If the file starts with '/' then it must be absolute. Otherwise, it is relative. Just tack it on to the end of the current working directory name, then collapse instances of "./" and "../".
You didn't say whether you are working on Unix or Windows, so you should be able to handle paths that start with a drive letter ("D:/foo/bar" is absolute, but "D:foo/bar" is relative) and that use '\\' and/or '/' as separators.
Personally, I would be inclined to split the path into a deque, manipulate its parts, then join it back together when done.
Hope this helps.
You didn't say whether you are working on Unix or Windows, so you should be able to handle paths that start with a drive letter ("D:/foo/bar" is absolute, but "D:foo/bar" is relative) and that use '\\' and/or '/' as separators.
Personally, I would be inclined to split the path into a deque, manipulate its parts, then join it back together when done.
Hope this helps.
Thanks again, Duoas. Both the server and the client will be on a Solaris (Unix) machine.
The object of this socket/network programming class is to keep things as barebone/simple as possible, so I don't think a deque is an option. Shouldn't the unix chdir function be able to handle both a relative and an absolute path?
The object of this socket/network programming class is to keep things as barebone/simple as possible, so I don't think a deque is an option. Shouldn't the unix chdir function be able to handle both a relative and an absolute path?
Last edited by Ratte; Nov 14th, 2007 at 12:12 am.
Sorry, I had just answered some questions in the C++ forum and forgot that this was the C forum, so a deque is unavailable in C...
Yes, the chdir() function can take both relative and absolute paths.
For parsing the paths I recommend you to the strpbrk() or strchr() functions (both defined in <string.h>).
Good luck.
Yes, the chdir() function can take both relative and absolute paths.
For parsing the paths I recommend you to the strpbrk() or strchr() functions (both defined in <string.h>).
Good luck.
![]() |
Similar Threads
- Retriving data from excel sheet into an asp page (ASP)
- file input problems (with windows?) (Java)
- Error in tables with OFF 2003 and XP sp2 (Visual Basic 4 / 5 / 6)
- Need help with HDD password (Storage)
- Save ME (Perl)
- unix/C++ segmentation fault (C++)
Other Threads in the C Forum
- Previous Thread: Recursive Backtracking Search Problem
- Next Thread: C program to calculate number of days between 2 dates using structure of pointers....
| Thread Tools | Search this Thread |
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer pointers posix power probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string strings structures suggestions systemcall test testautomation unix urboc user voidmain() wab win32api windows.h






