Re: gets() question
- Posted by Brian Broker <bkb at CNW.COM> Apr 05, 2000
- 460 views
On Wed, 5 Apr 2000 13:56:36 -0400, SR Williamson wrote: >I'm trying to read in the name of several movies, one on each line, to a >sequence. gets() seems to be reading only the first character. Here's the >code: > >object tempMovies >integer numMovies >sequence movieNames >movieNames = {} > > for i = 1 to numMovies do > tempMovies = gets(filenum) > movieNames = movieNames & tempMovies > end for > >???? This example is obviously incomplete but it is the correct way to read the movie names from a file (where each movie name is on it's own line) and put them into a sequence. (Note: that the names in the sequence will all have a linefeed ('\n') at the end.) But the question is: How are you determining that it is only reading the first character. If you are printing the contents of the sequence using printf, then note the following from the reference manual: Comments: Watch out for the following common mistake: name="John Smith" printf(1, "%s", name) -- error! This will print only the first character, J, of name, as each element of name is taken to be a separate value to be formatted. You must say this instead: name="John Smith" printf(1, "%s", {name}) -- correct Now, the third argument of printf() is a one-element sequence containing the item to be formatted. Hope this answered your question... -- Brian