Prophecy Posted December 5, 2002 Share Posted December 5, 2002 This is a program I writing for a class, What the program is supposed to do now is: Prompt the user for the number of names it will be inputting. Prompt the user for the name of the file in where the names are stored (EXAMPLE C:names.txt) Then take the names and input the names into the array. Then print the contents of the array. Could someone help me with INPUT FUNCTION, how do I get the names in the imported file into the array. syntax please? Also please excuse any bad programming you see this is one of my first assignments. Thanks Proph DECLARE FUNCTION Printline! (aline$)DECLARE FUNCTION Getfilename$ () DECLARE FUNCTION Readfile! (filename$) DECLARE SUB fillarray (A$(), size%) DECLARE SUB printarray (A$(), size%) DECLARE FUNCTION gethowmany% () CLS howmany% = 0 howmany% = gethowmany% filename$ = "" filename$ = Getfilename$ DIM stuff$(howmany%) CALL fillarray(stuff$(), howmany%) CALL printarray(stuff$(), howmany%) SUB fillarray (A$(), size%) FOR counter% = 1 TO size% INPUT "Please enter a name "; A$(counter%) NEXT counter% END SUB FUNCTION Getfilename$ filename$ = "" PRINT INPUT " what is the name of the input file "; filename$ Getfilename$ = filename$ END FUNCTION FUNCTION gethowmany% temp% = 0 INPUT "Please input the number of names you will be inputing "; temp% gethowmany% = temp% END FUNCTION SUB printarray (A$(), size%) FOR counter% = 1 TO size% PRINT A$(counter%) NEXT counter% END SUB FUNCTION Printline (aline$) PRINT aline$ END FUNCTION FUNCTION Readfile (filename$) OPEN filename$ FOR INPUT AS #1 IF EOF(1) THEN PRINT PRINT "sorry, your file was empty" ELSE PRINT PRINT "These are the names in the file" PRINT WHILE NOT (EOF(1)) INPUT #1, name$ IF (LEN(NNAME$) <> 0) THEN temp = Printline(name$) END IF WEND END IF CLOSE #1 END FUNCTION Link to comment Share on other sites More sharing options...
0 neowin_hipster Posted December 5, 2002 Share Posted December 5, 2002 I assume that you've called Readfile somewhere else right? An easy way to do it is in the calling level do a for loop kinda like so: (pardon my syntax, i haven't programmed basic in a while). I don't know how pointers and that work in qbasic otherwise i could do it differently but for now i'm keeping the readfile all in one function. OPEN filename$ FOR INPUT AS #1 for n=0 to howmany% 'isn't % double rather than int, if EOF(1) then break input #1,stuff$(n%) next n CLOSE #1 Link to comment Share on other sites More sharing options...
Question
Prophecy
This is a program I writing for a class, What the program is supposed to do now is:
Prompt the user for the number of names it will be inputting.
Prompt the user for the name of the file in where the names are stored (EXAMPLE C:names.txt)
Then take the names and input the names into the array.
Then print the contents of the array.
Could someone help me with INPUT FUNCTION, how do I get the names in the imported file into the array.
syntax please?
Also please excuse any bad programming you see this is one of my first assignments.
Thanks
Proph
Link to comment
Share on other sites
1 answer to this question
Recommended Posts