1. File I/O problems! Help!
- Posted by keiser <keiser at KEISER.EZL.COM> Mar 14, 1997
- 976 views
Here is the program src: include get.e object a integer b, c b = 0 b = open("c:\\euphoria\\code\\test.dat", "r") c = open("c:\\euphoria\\code\\test.txt", "w") a = gets(b) puts(c, b) close(b, c) puts(1, "Done.\n") Now, when I run it, i get this error: read.ex:9 bad file number (-1) -->see ex.err Ok, ex.err: Global & Local Variables C:\EUPHORIA\INCLUDE\get.e: input_file = <no value> input_string = <no value> string_next = <no value> ungot_char = <no value> read.ex: a = <no value> b = -1 c = 3 What did I do wrong, and can someone show me the correct way to do read/write programs (simple ones like this.). Thanks.
2. Re: File I/O problems! Help!
- Posted by "Lucius L. Hilley III" <luciuslhilleyiii at JUNO.COM> Mar 14, 1997
- 989 views
On Fri, 14 Mar 1997 01:10:02 -0800 keiser <keiser at KEISER.EZL.COM> writes: > >Here is the program src: > 1>include get.e 2> 3>object a 4>integer b, c 5>b = 0 6>b = open("c:\\euphoria\\code\\test.dat", "r") 7>c = open("c:\\euphoria\\code\\test.txt", "w") 8> 9>a = gets(b) 10>puts(c, b) 11>close(b, c) 12>puts(1, "Done.\n") >Now, when I run it, i get this error: >read.ex:9 This tells you that the error is on line 9. As you can tell from above. That line tries to read from the file you opened for reading! >bad file number (-1) This file number is file number that was returned. If you look in the documentation you will notice that -1 means that it failed to open the file. NOW you may have a share / lock problem associated with Windows OR MOST likely you simply specified the wrong path or file name. >-->see ex.err (some other values) > read.ex: > a = <no value> > b = -1 > c = 3 As you can see here again. You were using b as the file handle for the file you were going to read in. Again the value of b is -1. This states that there was an error in opening the file. --Lucius Lamar Hilley III -- E-mail at luciuslhilleyiii at juno.com -- I support transfering of files less than 64K. -- I can Decode both UU and Base64 format.
3. Re: File I/O problems! Help!
- Posted by Ad Rienks <Ad_Rienks at COMPUSERVE.COM> Mar 15, 1997
- 989 views
>On Fri, 14 Mar 1997 01:10:02 -0800 keiser <keiser at KEISER.EZL.COM> writes: > >>Here is the program src: >> 1>>include get.e 2> 3>>object a 4>>integer b, c 5>>b = 0 6>>b = open("c:\\euphoria\\code\\test.dat", "r") 7>>c = open("c:\\euphoria\\code\\test.txt", "w") 8> 9>>a = gets(b) 10>>puts(c, b) 11>>close(b, c) 12>>puts(1, "Done.\n") >>Now, when I run it, i get this error: >>read.ex:9 >This tells you that the error is on line 9. >As you can tell from above. That line tries to read from the file >you opened for reading! >>bad file number (-1) >This file number is file number that was returned. >If you look in the documentation you will notice that -1 means >that it failed to open the file. >NOW you may have a share / lock problem associated with >Windows OR >MOST likely you simply specified the wrong path or file name. >-->see ex.err >(some other values) >> read.ex: >> a = <no value> >> b = -1 >> c = 3 >As you can see here again. You were using b as the file handle >for the file you were going to read in. Again the value of b is -1. >This states that there was an error in opening the file. >--Lucius Lamar Hilley III In addition to what Lucius wrote, I would say the following: 1. When you want to open a file for reading, it has to exist allready. Logically. If it does not exist, the error code '-1' is also returned. 2. In line 10 I think you mean to say: puts(c, a). puts(c, b) would only write the file number. 3. Finally, in line 11 you use close(b, c). This is not possible in Euphoria. You have to close each file individually. Regards, Ad Rienks.