Mail Archives: djgpp/2001/06/18/11:30:04
From: | "Graham Reeds" <grahamr AT ntlworld DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Extracting a directory name.
|
Lines: | 33
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Newsreader: | Microsoft Outlook Express 5.50.4133.2400
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.50.4133.2400
|
Message-ID: | <u0pX6.32176$9t5.2935940@news6-win.server.ntlworld.com>
|
Date: | Mon, 18 Jun 2001 16:22:10 +0100
|
NNTP-Posting-Host: | 62.254.81.186
|
X-Complaints-To: | abuse AT ntlworld DOT com
|
X-Trace: | news6-win.server.ntlworld.com 992877722 62.254.81.186 (Mon, 18 Jun 2001 16:22:02 BST)
|
NNTP-Posting-Date: | Mon, 18 Jun 2001 16:22:02 BST
|
Organization: | ntlworld News Service
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
I have a piece of code which isn't working, and I can't think for the life
of me why. I have isolated the fault down to these lines with my
error-checking (printf()s) still in:
Ptr = strrchr(Directory, '\\');
bytestocopy = strlen(Directory) - strlen(Ptr);
printf("%i\n", bytestocopy);
strcpy(FileName, Ptr+1);
strncpy(BaseDir, Directory, bytestocopy);
printf("BaseDir: %s (%li)\n", BaseDir, strlen(BaseDir));
All the code does is take in a Directory (i.e: 'temp\downloads' or
'temp\downloads\images') and return the last path after the slash (using the
previous examples 'downloads' and 'images'). This works. However I also
need the info before the slash, and this is the piece that isn't working.
The amount to copy is strlen(Directory) - strlen(Ptr) but for some reason
always appends 2 extra bytes to the end or assorted gibberish (in the first
example I've got 'tempÛç'). I've tried to append a null byte to terminate
it with strcat() but that doesn't do anything either. I've got a feeling
I've probably missed something very basic, and it is beginning to frustrate
me.
Any ideas why?
--
Thanks, Graham Reeds.
- Raw text -