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:52 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

News: Join our IRC channel: ##psp-programming on freenode
Home Help Search Shop Login Register
Digg This!
Pages: [1] 2 3 4
Print
Author Topic: [Tutorial] File I/O  (Read 47501 times)
harleyg
Give miinaturvat Points!
Full Member
***

Karma: +11/-14
Offline Offline

Posts: 231
0.00 points

View Inventory
Send Money to harleyg

View Profile
« on: May 22, 2006, 06:48:00 AM »

removed
« Last Edit: November 22, 2011, 08:30:43 PM by harleyg » Logged


kozine
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 46
0.00 points

View Inventory
Send Money to kozine

View Profile WWW
« Reply #1 on: May 22, 2006, 08:34:08 AM »

Sweet Very Happy Thanks for this! It will help me alot Smile
Logged

Yeldarb
Miinaturvat Rules!
Administrator
Hero Member
*

Karma: +16/-3
Offline Offline

Posts: 601
4152.65 points

View Inventory
Send Money to Yeldarb


View Profile WWW
« Reply #2 on: May 22, 2006, 09:39:04 AM »

Nice =)

When it's all done, do you mind if I convert it to tutorial form and put it in the tutorials section where it'll get more traffic?
Logged

Feldor
Newbie
*

Karma: +1/-0
Offline Offline

Posts: 47
0.00 points

View Inventory
Send Money to Feldor


View Profile
« Reply #3 on: May 22, 2006, 10:27:10 AM »

well done, very usefull
Logged


All my work is licensed under the Creative Commons (CC) License.
phacergei
Jr. Member
**

Karma: +2/-1
Offline Offline

Posts: 63
0.00 points

View Inventory
Send Money to phacergei


View Profile
« Reply #4 on: May 22, 2006, 02:20:02 PM »

Very nice tutorial! I was actually about to make a tutorial on this stuff, because I am still fiddling around with PSP c programming. I made a basic text reader thing that does a similar function with outputting a text file. Your tutorial is much better than mine would have been, though.

Question: can you do "malloc()" on the PSP? I didn't think the PSP had that capability and I didn't want to risk messing it up by trying.

Also, what do you do if you have a text file that is very large (like an ebook or something), and won't display on the screen?

I found that the PSP screen is approximately 67 characters by 34 characters



 What I currently have is something like this:
Code:
char buffer[33][1000];
FILE* book;
int pg_index=0;
void Next_Page()
{
    pg_index=0;
    oslCls();
    while (fgets(buffer[pg_index], 67, book) && (pg_index < 33)) pg_index++;
    Show_Text(pg_index);
}
void Show_Text(int cmd)
{
    oslCls();
    int i;    
    oslSetTextColor(RGBA(0,0,0,255));
    oslSetBkColor(RGBA(255,255,255,255));
    if (cmd==0) oslPrintf_xy(30, 10, "No book loaded or end of book. Press square to load a book.\n\n");
    if (cmd) for(i=0; i<cmd; i++) oslPrintf("%s\n", buffer[i]);
}




So when I press x, it calls Next_Page, which reads from the file into a 2D char array, and then calls Show_Text with how many lines it read, and Show_Text oslPrintf's the lines...


It doesn't seem to work right, though


ergei
Logged
SG57
Sr. Member
****

Karma: +7/-37
Offline Offline

Posts: 474
1140.80 points

View Inventory
Send Money to SG57


View Profile
« Reply #5 on: May 22, 2006, 03:36:08 PM »

well... just setup a function...  have it 'check' to see if the string has reached 64 characters or not, then just inject a '\n' into it on the 64th char and ur done Smile  Unless you want the whole word to be carried... that requires parsing and searching from 1 ' ' to the next ' ' which would drag what ever is between down with it...

I know my string manipulation Wink
Logged
phacergei
Jr. Member
**

Karma: +2/-1
Offline Offline

Posts: 63
0.00 points

View Inventory
Send Money to phacergei


View Profile
« Reply #6 on: May 22, 2006, 03:47:19 PM »

well, yeah its an array of 33 strings and each is up to 67 chars long. I will make it 64 by 32 to make it even, but it should work anyway... The first page of the book displays perfectly fine, but when I press x to go to the next page, it looks fine, but It has skipped a bunch of lines.  It could be that it's skipping an entire page, I will check my code again.



ergei
Logged
Yeldarb
Miinaturvat Rules!
Administrator
Hero Member
*

Karma: +16/-3
Offline Offline

Posts: 601
4152.65 points

View Inventory
Send Money to Yeldarb


View Profile WWW
« Reply #7 on: May 23, 2006, 09:17:21 AM »

Not sure what's wrong :-\

I don't have access to the apache2.conf, nor do I know what I'd need to change.

Umm, I put it directly into mysql but it doesn't display correctly.
Logged

Yeldarb
Miinaturvat Rules!
Administrator
Hero Member
*

Karma: +16/-3
Offline Offline

Posts: 601
4152.65 points

View Inventory
Send Money to Yeldarb


View Profile WWW
« Reply #8 on: May 23, 2006, 01:08:05 PM »

It's a shared server.
Logged

Yeldarb
Miinaturvat Rules!
Administrator
Hero Member
*

Karma: +16/-3
Offline Offline

Posts: 601
4152.65 points

View Inventory
Send Money to Yeldarb


View Profile WWW
« Reply #9 on: May 24, 2006, 06:17:12 AM »

That was a pain in the ass  Confused
Logged

Yeldarb
Miinaturvat Rules!
Administrator
Hero Member
*

Karma: +16/-3
Offline Offline

Posts: 601
4152.65 points

View Inventory
Send Money to Yeldarb


View Profile WWW
« Reply #10 on: May 30, 2006, 02:07:00 PM »

Ok, I'm working on getting yours, vaza's, and a few other misc tutorials into the tutorial section right now.
Logged

Yeldarb
Miinaturvat Rules!
Administrator
Hero Member
*

Karma: +16/-3
Offline Offline

Posts: 601
4152.65 points

View Inventory
Send Money to Yeldarb


View Profile WWW
« Reply #11 on: May 31, 2006, 08:59:10 AM »

Fixed the problem =)

Stupid apache mods...
Logged

Yeldarb
Miinaturvat Rules!
Administrator
Hero Member
*

Karma: +16/-3
Offline Offline

Posts: 601
4152.65 points

View Inventory
Send Money to Yeldarb


View Profile WWW
« Reply #12 on: May 31, 2006, 02:18:10 PM »

Are there any extra LIBS that need to be linked in the Makefile?  (I'm adapting it to be PSP C code)

Edit:
Here's what I've got: http://www.psp-programming.com/tutorials/c/file_input_1.htm
Logged

Ryalla
harleyg
Hero Member
*****

Karma: +50/-12
Offline Offline

Posts: 813
9999999.99 points

View Inventory
Send Money to Ryalla


View Profile
« Reply #13 on: May 31, 2006, 02:21:22 PM »

Quote from: "Yeldarb"
Are there any extra LIBS that need to be linked in the Makefile?  (I'm adapting it to be PSP C code)

Edit:
Here's what I've got: http://www.psp-programming.com/tutorials/c/file_input_1.htm
Nope. I just tested them out. All work 100% right off the bat. There's no makefile needed if you just gcc it. ;D
Logged
Yeldarb
Miinaturvat Rules!
Administrator
Hero Member
*

Karma: +16/-3
Offline Offline

Posts: 601
4152.65 points

View Inventory
Send Money to Yeldarb


View Profile WWW
« Reply #14 on: May 31, 2006, 02:30:42 PM »

It's gotta be aimed at the PSP, this is PSP-programming.com after all Wink

If it's a general C tutorial and I put it up all that's going to happen is the forums will be flooded with people saying "I can't get this to work on my PSP"
Logged

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.245 seconds with 38 queries.
Sister Sites: Guitar Hero 4   BrokeniTouch.com