views:

47

answers:

3

I'm now taking a look at the PocketC powerful tool, but there is an fileopen function, that generates a integer called filehandle, that is used for most of the File I/O operations of PocketC. How do I use this int filehandle to call the other file manipulation functions?

Here is my example function that I'm using at my program:

fileopen("\test.txt", 0, 0x00000000);

Description of int filehandle: Integer used for file operations, used as a pointer to the fileopen instruction.

A: 

According to the documentation, fileopen RETURNS the filehandle as an int.

fileopen(string filepath, int type, int flag) :  open a file in unicode/ascii. 
You can create a new file or simply open one. Please use the flag correctly.

...

Return: Returns an integer as the File Handle if successful,otherwise -1, 
Remember to keep this handle value somewhere, 
Because you have to use this handle for the rest of file operations.

Joe
I know this, but I want to know which integer(the number that it's stored) is this! To know what to type on the other file operations functions. Also, I already knew this, because I have the docs here on my computer!
Nathan Campos
@Nathan, you need to clarify your question. Are you asking how to pass this returned `filehandle` to the other file operation functions?
Nick Meyer
Yeah, I need to know which number it will return if it works(not fail and return -1).
Nathan Campos
@Nathan, that's clearer -- please see my answer.
Nick Meyer
@Nathan. I think you are misunderstanding how filehandles work. They aren't a number you can just memorize. They are like memory addresses. They change every time you run it.
Earlz
+2  A: 

What do you mean discover the int filehandle? Your question is very vague.

Do you mean you want this?

int filehandle;
filehandle=fileopen("\test.txt", 0, 0x00000000); //PocketC may not like inline declarations. 
Earlz
Won't work. **:-(**
Nathan Campos
@Nathan won't work as in how? Runtime error or compiler error? What's the error message?
Earlz
I got this Compiler Error: `Variable int values must be const values, ex: int x = 5; int y = 7;`
Nathan Campos
@Nathan ok, now I'm stumped. This is now clearly a PocketC specific question, so I untagged C. I edited my question in a last attempt of fixing it though
Earlz
@Nathan, post some code for where you do the assignment of the return value. Are you attempting to declare the variable and assign it in the same action? That might not be allowed based on the crappy documentation. It would help if you were using a modern language that's actually supported.
Joe
@Joe, I'm not even sure if it qualifies as documentation ;)
Earlz
Thanks Earlz! It works now! **:D**
Nathan Campos
+1  A: 

The value returned by fileopen on success will be different each time -- that's the point of returning a handle, to uniquely identify a resource. If it returned the same value each time, you would have no way to distinguish the different files you had opened.

You need to save the value like Earlz suggested and then pass the saved variable to the other file manipulation functions.

Nick Meyer
@Nick, so easy you just have to make it CW right? :)
Earlz
@Earlz did I do that?
Nick Meyer
@Earlz: See my comment on your post.
Nathan Campos
@Nick, oh I wasn't aware nathan made it a CW question.
Earlz