Wednesday, December 5, 2007

Difference Between Mexican And Regular Oregano

11) info function (Write to File)


The first function that will illustrate to write something on a file. We simply write letters numbers or symbols, that is what we can type keyboard.
This feature is in a library and then to use it we must include it in the source with the command:



# include pspiofilemgr.h
> < Going to order, we must have a file open to write something. First declare a variable " SceUID fd"
fd is a given name, a name you can put any work. To open a file we have to use a feature included in the same library:


SceUID sceIoOpen (const char * file, int flags, SceMode mode)


This function returns the value SceUID we open the file. It accepts 3 parameters:


const char * file , the full path of the file to open

  • int flags, the way in which to open the file ("
    O_RDONLY"
  • = read-only if we just read from that file or " O_WRONLY how it works but in doubt, do not ever go wrong by setting the value "0777". If I had to understand what good will post certainly 'more! If sceIoOpen report one 0, it means that the 'file open is not successful because of some error. to initialize fd So now, using this function, write this:
  • fd = sceIoOpen ("ms0: / file.txt",
O_RDONLY, 0777
)
Now fd "contains the 'address" file open and we can use this function with sceIoWrite that writes to a file.


This function returns an integer, the number of bytes written. As just one example ... byte corresponds to a symbol (including space), letter or number. Then the function is: int
sceIoWrite

(SceUID fd, const void * data, SceSize size); accepts 3 parameters: SceUID fd, fd is a variable called type SceUID. We say that this is stored the file open, to be able to do something. So before you call


sceIoWrite us ensure that they have opened a file and have created and initialized this variable. Obviously fd is a given name, then you can call whatever you want!




    const void * data, this pointer contains data to write. In our case we will write one or more characters. So you can call the function passed as an attribute letter or character string.
  • SceSize size, this is the size of what we write. I repeat that in the case of writing characters and strings, this value is equal to the number of characters including the space.
  • Finally, after writing our string we should close the file to save the whole. This we must do so with the function:
sceIoClose
(fd);
  • So we close the file and save it.
That's the theory. Now on to practice with a simple code that shows everything. Let's create a function that writes something on the file:



scrivo_su_file void (const char * file_path, const char * string) {


SceUID fd;


/ * are the I create the file does not exist (thanks to 'option PSP_O_CREAT

) * / fd =

sceIoOpen ( file_path

, PSP_O_WRONLY
sceIoWrite (fd, string, strlen (string));


sceIoClose (fd);}



To compile a source with this feature, you do not need any added to the Makefile , then you can use this very well:
TARGET = file1 OBJS = main.o CFLAGS =-O2-G0-Wall CXXFLAGS =
$ (CFLAGS)-fno-exceptions-fno- rtti
ASFLAGS = $ (CFLAGS)
EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = Input File Tutorial 1
PSPSDK = $ (shell / usr / local / pspdev / bin / psp-config - Pspsdk-path) include $
(PSPSDK) / lib / build.mak






You can test this function in your sources and how to best use it. There's nothing better than the 'direct experience ...




This tutorial is over, but to conclude that there is to say we can open the file in various ways. We have illustrated the simplest, which are read and write ...

Below is a list of all possible ways to open a file ("int flags") and I know I point out what they do:










PSP_O_RDONLY (Read Only)






PSP_O_WRONLY (WRITE ONLY)

PSP_O_RDWR (READ + WRITE)

PSP_O_NBLOCK


PSP_O_DIROPEN
  • PSP_O_APPEND (I open and write down the file)
  • PSP_O_CREAT (create files, or overwrite, and open it in WRITING)
  • PSP_O_TRUNC
  • PSP_O_EXCL
  • PSP_O_NOWAIT
  • I hope I was clear. For any errors or clarification is my email. I hope now that it has completed the basic "things" about the world of C programming on the PSP. From now introduce further information and / or explanations of the various libraries usable to do specific things.
  • Thanks to BigBoss, because I was inspired by his leadership to create this!

0 comments:

Post a Comment