how can i make my prog. accepts only 'y' &'n' char?
i really dont know what to do.
any help much appreciated.
Do not double post, be patient and explain better your problem in such a way as more people can understand what you are trying to do and in what context and maybe this way you will get more answers faster.
You give too little context ... is this a windows or a dos application? is this a GUI or a console application? 32 bits or 16 bits or 64 bits?
Basically:
1) read key from user
2) compare key with "y"
3) if compare is equal then execute code for this case
4) if not then compare key with "n"
5) if compare is equal then execute code for this case
6) else emit an error message because key is not "y" or "n"
The exact specifics depend a lot on you giving more info...
And BTW we do not solve homework, this is a rule here
REMINDER
If your program is to be used by other than yourself alone, don't repeat the same error as some programmers used to do. Also check if the input is one of the upper case letters in addition to the lower case letters. There's nothing more aggravating than pressing "Y" (or "N") repeatedly and nothing happens. :boohoo:
easy way is to simply force upper or lower case
Quote from: raymond on October 05, 2010, 12:43:34 AM
There's nothing more aggravating than pressing "Y" (or "N") repeatedly and nothing happens. :boohoo:
cmp al, 'Y'
je RTFS
cmp al, 'N'
je RTFS
RTFS:
print "RTFS.... Press 'y' or 'n'.... I dont know why I bother sometimes.... I might as well do it all myself and tell you when I'm done.... You dont listen to a word I say...."
and al,0DFh ;force upper case
cmp al, 'Y'
je RTFS
cmp al, 'N'
je RTFS
If you are using a GUI application and the program stops for user input you can use a message box with the MB_YESNO style, it will only display a yes and no button and will return IDYES or IDNO as results (IDYES being the default).
Edgar
You can also intercept the message loop and:
Quote
.elseif uMsg == WM_CHAR ;keyboard
.if wParam == "Y" || wParam == "y"
for a control , you have to use this
Quote
INVOKE SetWindowLong, Hredit, GWL_WNDPROC, EventRichEdit
Then create "EventRichEdit" the proc for events
Fascinating topic... 154 views and 8 answers so far :wink
include \masm32\include\masm32rt.inc
.code
AppName db "Masm32:", 0
start:
@@: print "Press y[es] or n[o]", 13, 10
getkey
or al, 32 ; lowercase
cmp al, "y"
je PressedYes
cmp al, "n"
jne @B
PressedNo:
inkey "Oh no..."
exit
PressedYes:
inkey "Oh yes..."
exit
end start
Quote
Fascinating topic... 154 views and 8 answers so far
Perhaps if the author can say he want to use this under:
Windows
Dos
In a windows or without window
Answers will be less numerous.
Hi stapo34,
Here is a quick example for you :
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
.data
msgtable dd OFFSET yes , OFFSET no
text1 db 'Hit yes or no',0
capt db 'Hello',0
yes db 'You pressed yes',0
no db 'You pressed no',0
.code
start:
invoke MessageBox,0,ADDR text1,ADDR capt,MB_YESNO
shl eax,2 ; eax = eax * 4
; IDYES = 6 , IDNO = 7
add eax,OFFSET msgtable - 4 * IDYES
invoke MessageBox,0,DWORD PTR [eax],ADDR capt,MB_OK
invoke ExitProcess,0
END start