Writte to file?(Devkitpro)

Discussion in 'NDS - Emulation and Homebrew' started by DragonRider, Mar 12, 2012.

Mar 12, 2012
  1. DragonRider
    OP

    Newcomer DragonRider Advanced Member

    Joined:
    Aug 25, 2011
    Messages:
    99
    Country:
    Austria
    Hello,
    can anyone tell me how i can writte something to a file using devkitpro (and c)?
    Thanks
     
  2. Foxi4

    Reporter Foxi4 On the hunt...

    pip
    Joined:
    Sep 13, 2009
    Messages:
    22,705
    Location:
    Gaming Grotto
    Country:
    Poland
    1. Initialize fatlib and create a FILE variable.
    2. Open a file
    3. fwrite your buffer

    Code:
    #include 
    
    fatInitDefault();
    
    FILE* aFile;
    char* buffer;
    
    chdir("fat:/YourPath");
    aFile = fopen ("aFileYouWantToCreate.Extension" , "wb" );
    fwrite (buffer , 1 , sizeof(buffer) , aFile );
    fclose (aFile);
    EDIT: Fixed
     
  3. DragonRider
    OP

    Newcomer DragonRider Advanced Member

    Joined:
    Aug 25, 2011
    Messages:
    99
    Country:
    Austria
    thank you :)
     
  4. Foxi4

    Reporter Foxi4 On the hunt...

    pip
    Joined:
    Sep 13, 2009
    Messages:
    22,705
    Location:
    Gaming Grotto
    Country:
    Poland
    It's a very simplified version - remember to malloc memory to the buffer. :)

    Code:
    buffer = malloc(sizeof(YourContent));
     
  5. DragonRider
    OP

    Newcomer DragonRider Advanced Member

    Joined:
    Aug 25, 2011
    Messages:
    99
    Country:
    Austria
    Thank you, but i get this error:
    ...../main.c:41: undefined reference to `fatDefau
    ltinit'

    How can i fix it?
     
  6. Foxi4

    Reporter Foxi4 On the hunt...

    pip
    Joined:
    Sep 13, 2009
    Messages:
    22,705
    Location:
    Gaming Grotto
    Country:
    Poland
    You are correct - I made a boo boo. It was supposed to be fatInitDefault(); not the other way around, correct that and it'll work. Sorry, routine kills sometimes. ;)

    Also, remember to change the makefile and #include the library if you still haven't:

    Code:
    Change line:
    
    LIBS:= -lnds9
    
    Into:
    
    LIBS:= -lfat -lnds9
    A useful read:

    http://chishm.drunke...ers.com/libfat/
     
  7. DragonRider
    OP

    Newcomer DragonRider Advanced Member

    Joined:
    Aug 25, 2011
    Messages:
    99
    Country:
    Austria
    hm, i still get the error :(
    Fixxed!

    That was my problem:


    You was faster xD


    Now it work!
    Thank you
     
  8. Foxi4

    Reporter Foxi4 On the hunt...

    pip
    Joined:
    Sep 13, 2009
    Messages:
    22,705
    Location:
    Gaming Grotto
    Country:
    Poland
    You sure you changed the line, #include'ed and written the correct code? By the way, remember that FAT doesn't work on emulators.

    EDIT: Great, I'm glad I could help. :) Sorry, sometimes I completely forget about the makefile, I have one pre-prepared one and I just copy-paste it to my projects so I completely forget about that part. ;)
     

Share This Page