Hi

I am having problem with the obtaining the length of a String.
I expect the following programme to print the length of the String
pass in from the StdIn to StdOut. However it always prints 2+the length
of the String passed.
For example if you pass 123 it will give you a string length of 5.


Omar

;########################Test.asm###########################
.486
.model flat, STDCALL
option casemap :none ; case sensitive

include \Masm32\include\windows.inc
include \Masm32\include\kernel32.inc
include \Masm32\include\Masm32.inc
includelib \Masm32\lib\Masm32.lib
includelib \masm32\lib\kernel32.lib



.data

pos DWORD 0
srcb Byte 20 dup(0),0

.code
start:
INVOKE StdIn, ADDR srcb, 20
INVOKE StrLen, ADDR srcb

INVOKE dwtoa, eax, ADDR pos
INVOKE StdOut, ADDR pos

invoke ExitProcess,0



end start

end

;############################################################
Posted on 2003-04-30 05:43:09 by shiny
This is probably because the "enter" token is added to the string
It consists out of a CR and a LF character.
Posted on 2003-04-30 05:57:52 by Guerrilla
Guerrilla has right,for example if we type "strlen":
Posted on 2003-04-30 12:14:29 by Vortex
It's very improbable that your posted prog would ever give you a problem when returning the length of a string.

However, you must realize that the dwtoa function expect the address of a text buffer as the 2nd argument. If you ever use that function with a positive number higher than 999 or a negative number with more than 2 decimal digits, make sure you pass it the address of a buffer larger than a DWORD.

Raymond
Posted on 2003-04-30 22:33:00 by Raymond
The solution is simple:

Your entering: "123"+Return

So your buffer is holding "31,32,33,0C,0D,00"

Hence 5 non-null characters... The MASM32.INC has a function "StripLF" which will pre-condition the buffer to: "31,32,33,00"

Hope this helps..
:alright:
NaN
Posted on 2003-04-30 22:43:38 by NaN
Thanks guys
Posted on 2003-05-02 07:28:54 by shiny