[OCLUG-devel] fopen doesn't like my path

Doug Jolley ddjolley at gmail.com
Sun Nov 20 12:11:03 PST 2005


I am using fopen to open two different files. In the first case (which works
just fine), I simply define the path to the file as 'char
path2file[]="/path/to/file"'. I then use path2file as the first argument to
fopen. In the second case (which doesn't work so well), I extract the path
to the file from colon-delimited data contained in a string using strtok.
IOW, I use the following 'path=strtok(NULL,":")'. I use NULL here because I
have previously extracted other tokens and the path is the next token to be
extracted. I inserted a printf statement to print 'path' and it does in fact
point to the correct data. However, when I put 'path' as the first argument
to fopen, I get a segmentation fault. If I replace the 'path' argument to
fopen with the actual correct path to the file (by just including the actual
string enclosed in double quotes), it works just fine. So, it certainly
appears that fopen doesn't like my path pointer which was derived from
strtok; but, I have absolutely no idea why. Can anyone help me out? Thanks
for any input.

... doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://localhost.localdomain/pipermail/oclug-devel/attachments/20051120/3ec68cff/attachment.html 


More information about the OCLUG-devel mailing list