- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Given the nul terminated string,
'C:\MyDir\MyProg.exe'C, I would like to
obtain the string 'C:MyDir'//ACHAR(0).
INTEGER iPos
CHARACTER(100) szPath
szPath = 'C:\MyDir\MyProg.exe'C
iPos = INDEX(szPath, '', BACK = .TRUE.)
! remove 'MyProg.exe'
szPath = szPath(1 : iPos-1)//ACHAR(0)
What result does the code above produce?
szPath = 'C:\MyDir'//ACHAR(0)
or
szPath = 'C:MyDir'//ACHAR(0)
Also, is there a way to get VS 2003 to display the Esc characters
in a nul terminated string. Currently VS displays
'C:\MyDir\MyProg.exe'C as 'C:MyDirMyProg.exe'
Thanks for any commentsinformation
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you are under the misapprehension that when you write
szPath='C:MyDirMyProg.exe'C
the extra backslashes are stored. That is not what happens.
The extra backslashes are used by the compiler to generate
the c-string 'C:MyDirMyProg.exe' with a null terminating character.
You can check this by testing the length of the string.
You will find that up to, but not including,the terminating null, it is
19 characters long, not 21.
So, given your code, you will finish up with the second result,
namely
szPath = 'C:MyDir'//ACHAR(0)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Anthony.
If 'C:MyDirMyProg.exe'is returned by aWin32function such as GetModuleFileName(NULL, szPath, MAX_PATH), I assume the same is true, and that the code above would produce 'C:MyDir'//ACHAR(0). Is this correct?
Trying to troubleshoot a memory access violation that appears to be related to the way I manipulate nul terminated strings, but not sure.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page