20

When you are getting INPUT in Commodore BASIC it always adds a question mark at the end of the string you want to show.

Is there a way to suppress the question mark when using the INPUT command?

1
  • 2
    Before others try it (I did!), it isn't like (say) AppleSoft BASIC where simply using the form INPUT "NAME: ";A$ would suppress the ? with your supplied prompt... it doesn't work.. it still puts the ? there despite supplying the quoted string for a prompt :-/
    – bjb
    Commented Oct 12, 2017 at 16:35

6 Answers 6

39

Use the INPUT# command.

The INPUT# command is meant for non-interactive I/O on files or devices, i.e. reading from a file on disk, serial port, whatever. Because it is non-interactive, it will not display a prompt anywhere. The keyboard can be opened like any other I/O device, it has device number 0. Knowing that, the implementation is straightforward.

10 OPEN 1,0:REM OPEN DEVICE 0 AS FILE #1
20 PRINT"TYPE SOME TEXT:";
30 INPUT#1,A$
40 PRINT"YOU TYPED:";A$

INPUT#

9

Back in the day I wrote my own input code using GET. Over time I enhanced it to support various features. You start out with GET A$. Here is a simple one I just threw together:

10 NA$="":PR$="Name:"
20 GOSUB 50000
30 PRINT"Your name is ";NA$
40 END

50000 PRINT PR$;
50010 GET A$:IF A$="" THEN 50010
50020 IF A$=CHR$(13) THEN PRINT:RETURN
50030 IF A$<>CHR$(20) THEN 50050
50040 IF LEN(NA$)>0 THEN NA$=LEFT$(NA$,LEN(NA$)-1):? CHR$(157);" ";CHR$(157);
50050 IF A$>="a" AND A$<="z" THEN 50090
50060 IF A$>="A" AND A$<="Z" THEN 50090
50070 IF A$=" " THEN 50090
50080 GOTO 50010
50090 NA$=NA$+A$:PRINT A$;:GOTO 50010

BITD I had a blinking cursor implemented.

4
  • 1
    Doesn't work. My name contains a hyphen! :)) SCNR
    – Raffzahn
    Commented Oct 12, 2017 at 19:51
  • chr$(20) is ctrl-T; was it used as a backspace instead of ctrl-H (chr$(8)) ?
    – Leo B.
    Commented Oct 13, 2017 at 2:03
  • 1
    @LeoB.: The INS/DEL key in the upper-right corner of the keyboard generates control-T, which is the normal way of doing a backspace. Cursor-left is character code 147 (decimal).
    – supercat
    Commented Oct 13, 2017 at 17:12
  • "50040 IF LEN(A$)>0" should probably be changed to "50040 IF LEN(NA$)>0" otherwise you get an error when you press Backspace when there is no string.
    – mobluse
    Commented Dec 26, 2022 at 23:16
6

POKE19,32 just before issuing the INPUT statement.

2
  • 1
    I like it, and I can guess what it's doing, but a little explanation would be welcome.
    – hobbs
    Commented Nov 11, 2018 at 3:35
  • 1
    Any number other than zero poked into address 19 would work for this. Address 19 contains the current I/O device. When it is other than zero, the operating system supresses the prompt. When using OPEN1,0:INPUT#1 A$:CLOSE1the effect is the same, with a monitor program one can see that address 19 contains a 1 when the INPUT# command is executed.
    – Peter B.
    Commented Jan 13, 2019 at 14:25
2
10 POKE 19,1   
20 INPUT "ENTER NAME : ";A$   
30 POKE 19,0   
40 PRINT:PRINT "YOUR NAME IS ";A$   
2

Is there a way to suppress the question mark when using the INPUT command?

No. There are also other problems with using INPUT to get keyboard input. The Commodore PET had a problem where just typing Return would stop the program which probably also exists on the C64. You might be better using the GET command.

1
  • 5
    The problem with the instant termination when pressing Return does not exist on the C64
    – user6734
    Commented Oct 12, 2017 at 13:35
1

Create your own custom input routine. The following one allows the input of letters A-Z and digits 0-9, although it could be further modified to limit the number of characters entered or to allow inserting the punctuation characters. The input string is stored in w$.

I am using VICE to write this program, so the underline characters in lines 20, 110, and 310 are achieved by pressing ShiftR.

5 print
10 w$=""
20 print "_";
30 get a$:if a$="" then 30
40 a=asc(a$)
50 if a=13 then 200:rem return
60 if a=32 then 110:rem space
70 if a=20 then 300:rem backspace
100 if a<48 or a>57 and a<65 or a>90 then 30
110 print chr$(20);a$;"_";
115 w$=w$+a$
120 goto 30
200 rem handle return
210 print chr$(20)
215 if w$="" then print:print"you typed nothing!":end
220 print:print"you typed: ";:print w$
230 end
300 rem handle backspace
305 if len(w$)=0 then 30
310 print chr$(20);chr$(20);"_";
320 w$=left$(w$,len(w$)-1)
330 goto 30

You must log in to answer this question.