Skip to: Site menu | Main content


Welcome to PSP-Programming.com, a place for developers to get together.

Welcome to the forums. Here you can find other user tutorials as well as homebrew releases and the source code repository. You can also ask for help with your code here and post your own homebrew!

PSP-Programming.com Forums
February 04, 2012, 08:32:34 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

News: Welcome to PSP-Programming.com
Home Help Search Shop Login Register
Digg This!
Pages: 1 2 [3] 4
Print
Author Topic: [Tutorial] File I/O  (Read 47501 times)
SG57
Sr. Member
****

Karma: +7/-37
Offline Offline

Posts: 474
1140.80 points

View Inventory
Send Money to SG57


View Profile
« Reply #30 on: June 20, 2006, 03:56:22 AM »

...hmm... off topic, but does the KKK have a symbol?  Or is it there whitehoods?  

anyway, so is the retro 80s piece sign Smile  it signifys alot of things...
Logged


whazilla
Sr. Member
****

Karma: +2/-8
Offline Offline

Posts: 377
1793.33 points

View Inventory
Send Money to whazilla


View Profile
« Reply #31 on: June 20, 2006, 04:52:46 AM »

i think it's hoodwinked

and oh yeah ... a cross witha circle ... reminds of a playstation symbol :p
Logged
Raphael
Global Moderator
Hero Member
*

Karma: +230/-10
Offline Offline

Posts: 1431
193700.11 points

View Inventory
Send Money to Raphael


View Profile WWW
« Reply #32 on: June 20, 2006, 09:32:36 AM »

Before being picky, better first do some deeper research...
Quote from: "SG57"
File Input (Reading) - 3. Searching to a certain point.

... i hate to say this harleyg, (cause u hate me enough) but...
ftell() returns a long - you have it as an integer.

For the PSP and any 32bit machine, int and long have the same size, so it doesn't matter. If this would be compiled for a 64bit architecture and run on a 64bit OS, it makes only little difference, because only filesizes up to 2Gb will be returned correctly. Well... nothing I would care about in a program where I know how big my files can be.

Quote

Why are you casting malloc() ?

Actually, casting malloc isn't wrong (esp. on PSP, since malloc is correctly returning void*). If you read through your posted thread more closely, you will see that it also has some specific advantages depending on programming style. And the latter is something that everyone has to choose for himself. In fact I cast malloc sometimes myself.

Quote

Why are you stuffing EOF into a char and not an int?

First, the link you give has absolutely nothing to do with the EOF returned by fgetc in C, it references the function eof in the TCL language. In stdio.h EOF is defined as -1, and as such can be held by a char. So this is absolutely legal, though not 100% correct (it could still be the case, though not very likely, that there is character with value -1 (0xff hex) in the file, which will cause the loop to end prematurely).
Also see sample code from http://www.cplusplus.com/ref/cstdio/fgetc.html

Quote

Why are you declaring a variable that you don't use (n)?

This is something that always happens to everyone, when revising one's code, for example when cleaning up for a tutorial or public release. If you would have some more experience, you would know this.

Quote
Why isn't there room for the NULL character?

This one is the only one really important criticism. It would be enough to just set buffer[size-x] = '\0' after the read, but kill the last byte.

Not much left of your criticism in the end.
Logged

Don't push the river, it flows.
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki
http://www.homebrew-illuminati.co.uk - serious homebrew development for all platforms
Alexander Berl
"A good mod is a combination playground monitor, priest, big brother/sister, psychiatrist, professor and more."
Raphael
Global Moderator
Hero Member
*

Karma: +230/-10
Offline Offline

Posts: 1431
193700.11 points

View Inventory
Send Money to Raphael


View Profile WWW
« Reply #33 on: June 20, 2006, 10:13:58 AM »

Well, he's young and wants to show-off, nothing else. And it works with anyone that has no clue about programming, but I only find myself grining. He has to learn that he's not yet good enough to talk so big.
Logged

Don't push the river, it flows.
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki
http://www.homebrew-illuminati.co.uk - serious homebrew development for all platforms
Alexander Berl
"A good mod is a combination playground monitor, priest, big brother/sister, psychiatrist, professor and more."
SG57
Sr. Member
****

Karma: +7/-37
Offline Offline

Posts: 474
1140.80 points

View Inventory
Send Money to SG57


View Profile
« Reply #34 on: June 20, 2006, 01:23:02 PM »

harleyg - you didnt back your code up Raphael did, so you dont have any room to talk...

Raphael - yes im young still, (14), so sue me...  Im trying and you have to admit, i made 'some' very good points for my age (?)...  Oh and to follow the 'recommeneded' usage of the libraries prototypes is a well thoguht out strategy becasue it gives you a good habit, where as, as an example, declaring ftell() as an 'int' will only work in those special cases you said already...

Anyway, glad that's all cleared up.
Logged
Raphael
Global Moderator
Hero Member
*

Karma: +230/-10
Offline Offline

Posts: 1431
193700.11 points

View Inventory
Send Money to Raphael


View Profile WWW
« Reply #35 on: June 20, 2006, 02:19:27 PM »

Quote from: "SG57"

Raphael - yes im young still, (14), so sue me...  Im trying and you have to admit, i made 'some' very good points for my age (?)...

I'm not sueing you for being young. Everyone was young once, the only difference is that some understand that their still limited experience and knowledge isn't enough to talk big and play smartass, while the others always try to do exactly that, though most of the time they just make a fool of themself. Unfortunately, you have tendencies to the latter.
Noticing such small inconsistencies to the definitions is a very good attribute for a future programmer and shows potential, but you need to get 100% sure that you're right before shouting 'you made a mistake!', especially if you still make very basic mistakes yourself (like on your other threads here and on PSPU/PS2Dev). That's just some wanna-be attitude, exactly as giving yourself big titles.

Quote

Oh and to follow the 'recommeneded' usage of the libraries prototypes is a well thoguht out strategy becasue it gives you a good habit, where as, as an example, declaring ftell() as an 'int' will only work in those special cases you said already...

Its correct to start from ground up with building a good programming habit for oneself. However, trying to tell others their programming habit is wrong/bad because it differs from your own is a bad social habit.
And these ftell cases aren't that special at all, it's rather the other way around, since we're on a psp-programming forum here.

In the end, it all just comes down to the way how you put down your ideas/criticism. You can try to be constructive and give hints on how to improve things and this will absolutely be accepted and also appreciated. However in your case it just sounded like you were trying to pick upon harleyg and that's something I don't like, and even more so when the picking isn't correct either.

I think you can become a good programmer once, but you need to get rid of your cheeky attitude, or else you won't be accepted by the better programmers, and only from them you can learn and get better yourself.
Logged

Don't push the river, it flows.
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki
http://www.homebrew-illuminati.co.uk - serious homebrew development for all platforms
Alexander Berl
"A good mod is a combination playground monitor, priest, big brother/sister, psychiatrist, professor and more."
SG57
Sr. Member
****

Karma: +7/-37
Offline Offline

Posts: 474
1140.80 points

View Inventory
Send Money to SG57


View Profile
« Reply #36 on: June 20, 2006, 04:32:36 PM »

harleyg - Seeing as how my age keeps coming up so many times with my programming techniques (I wasn't planning on bringing my age up), I'd say I can use my age as an excuse...

Raphael - I wasn't being a smart ass or anything, I even said to not get mad, but when I looked through and saw some things wrong in the code, I posted what I had seen...  Also, harleyg had said himself that this is 'general' C and yeldarb had just converted it to match PSP Specific I/O Standards to use in the tutorial...  So yes, Id say since this 'thread' is pretty much only General C, ftell()'s return value should be a long, which is important for use on cross-platforms.
Logged
gamehunter101
Full Member
***

Karma: +3/-1
Offline Offline

Posts: 180
0.00 points

View Inventory
Send Money to gamehunter101


View Profile WWW
« Reply #37 on: June 20, 2006, 04:52:18 PM »

Lets just all respect each other and chill alittle Cool  Cool
Logged

Raphael
Global Moderator
Hero Member
*

Karma: +230/-10
Offline Offline

Posts: 1431
193700.11 points

View Inventory
Send Money to Raphael


View Profile WWW
« Reply #38 on: June 20, 2006, 05:23:04 PM »

Quote
ftell()'s return value should be a long, which is important for use on cross-platforms.

Well, technically ok, but it's still not really wrong to cast it to int there, it will only return wrong filesizes/file positions when above 2Gb. I don't think that is something beginners are working with, exactly like cross-plattform compatibility Smile
But I don't wanna argue any more on this, I just wanted to give you my opinion on some of your attitude in the last post.
Logged

Don't push the river, it flows.
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki
http://www.homebrew-illuminati.co.uk - serious homebrew development for all platforms
Alexander Berl
"A good mod is a combination playground monitor, priest, big brother/sister, psychiatrist, professor and more."
SG57
Sr. Member
****

Karma: +7/-37
Offline Offline

Posts: 474
1140.80 points

View Inventory
Send Money to SG57


View Profile
« Reply #39 on: June 20, 2006, 10:43:09 PM »

Quote
So yes, Id say since this 'thread' is pretty much only General C, ftell()'s return value should be a long, which is important for use on cross-platforms.
Try again harleyg.

Do you really want to start all this again?
Logged
Waterbottle
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 34
16.37 points

View Inventory
Send Money to Waterbottle

View Profile
« Reply #40 on: July 04, 2006, 07:32:12 PM »

I'm not sure if I should ask this here..  But I guess it involves fileI/O so I'll do it here:

How can I read what a files timestamp is?
Logged

Waterbottle
Insert_Witty_Name
Global Moderator
Hero Member
*

Karma: +149/-17
Offline Offline

Posts: 1602
1141.66 points

View Inventory
Send Money to Insert_Witty_Name

View Profile WWW
« Reply #41 on: July 05, 2006, 12:20:56 AM »

Quote from: "Waterbottle"
I'm not sure if I should ask this here..  But I guess it involves fileI/O so I'll do it here:

How can I read what a files timestamp is?


I was interested in this too so I gave it a go.

I made an example that worked perfectly on the PC - but gave incorrect date/time on the PSP.

This link contans everything you need to know - plus an example program.

http://cermics.enpc.fr/~ts/C/FUNCTIONS/stat.html

I'm sure it's probably me - I've just got home from a 12 hour night shift, so I could be a little tired  Shocked
Logged

Coder formerly known as:

Check out my homebrew & C tutorials at http://insomniac.0x89.org
Last updated 6th Oct 06 - Tutorial 2 added.
ai3gtmc
main () C & LUA CODER end
Newbie
*

Karma: +10/-47
Offline Offline

Posts: 42
97.39 points

View Inventory
Send Money to ai3gtmc

Hmmm What?


View Profile
« Reply #42 on: April 20, 2007, 09:03:08 PM »

the links for the I/O are down Confused
Logged

gb009
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 7
577.78 points

View Inventory
Send Money to gb009

View Profile
« Reply #43 on: March 03, 2008, 05:06:51 PM »

Hi,

I get the following error when I try to compile the first program in this tutorial:
$gcc main.c
/cygdrive/c/DOCUME~1/gb/LOCALS~1/Temp/ccCFKDIk.o:main.c:(.text+0x6a): undefined reference to '_fseel'
collect2: ld returned 1 exit status



I am posting the code below:
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
   FILE *pFile;
   long lSize;
   char * buffer;

   pFile = fopen("myfile.txt", "rb");

   if(pFile==NULL)
   {
      exit(1);
   }
   fseel(pFile, 0, SEEK_END);
   lSize = ftell(pFile);
   rewind(pFile);

   buffer = (char*) malloc (lSize);
   if(buffer == NULL)
   {
      exit(2);
   }

   fread(buffer,1,lSize,pFile);

   fclose(pFile);

   printf("%s\n", buffer);

   free(buffer);

   return 0;
}


what i am using:
Cygwin with PSPSDK.

command used to compile : gcc main.c

Logged
BigBlack
**PSP-Programmer**
Full Member
***

Karma: +8/-2
Offline Offline

Posts: 109
6867.63 points

View Inventory
Send Money to BigBlack


View Profile WWW
« Reply #44 on: March 03, 2008, 06:28:57 PM »

The Problem is here":
Code:
   fseel(pFile, 0, SEEK_END);
It Should be:
Code:
   fseek(pFile, 0, SEEK_END);

 Very Happy It's an understandable typo.
Logged

Hacked PSP
Formerly Known as 'ttotto'

Hombrew in progress:
PSNP (check out my website)
Going to be added to EZPSP LIb

*EZPSP library*
http://www.psp-programming.com/forums/index.php?topic=2935.

!NEW!
Member kenkai has givin me inspiration to start on rebuilding EZPSP Library!!!!
Pages: 1 2 [3] 4
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.234 seconds with 39 queries.
Sister Sites: Guitar Hero 4   BrokeniTouch.com