C/C++ Programming Help Thread
This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Ok, so I'm trying to find a string in a txt file and add a new line after it. Here's ...
-
07-15-2009, 04:55 PM #9871QJ Gamer Green
- Registriert seit
- Nov 2008
- Ort
- Portugal
- Beiträge
- 20
- Points
- 6.205
- Level
- 51
- Downloads
- 0
- Uploads
- 0
Ok, so I'm trying to find a string in a txt file and add a new line after it.
Here's a part of the code, but it's not working how it should.. It adds the RplcText to the end of the file instead of replacing the SrchText..
test.txt file:
123
abc
def
789
What am I doing wrong?
Code:FILE *fg; int i=0,len_string; char SrchText[]="abc"; char RplcText[]="acb\n456"; char tmp[20]; fg=fopen("test.txt","a+"); rewind(fg); if(fg==NULL) { printf("Error openning the file."); exit(0); } len_string=strlen(SrchText); while(1) { for(i=0;i<len_string;i++) tmp[i]=fgetc(fg); tmp[i+1]=NULL; if(stricmp(SrchText,tmp)==0) { fprintf(fg,"%s ",RplcText); fclose(fg); exit(1); } fseek(fg,-(len_string-1),1); } fclose(fg);
-
07-15-2009, 05:51 PM #9872
you basically need to read the entire file into memory in a linked list say, and insert the line and write it all back to disk. binary files are absolute, there is no easy way to just insert text right in the middle, you need to move everything that comes after it down.
-- Code Monkey : Sarien, Fishguts, Cracks and Crevices --
"Did IQ's just drop sharply while I was away?" (Ripley)
-
07-15-2009, 06:17 PM #9873Developer
- Registriert seit
- Jul 2008
- Ort
- Grand Rapids! MI
- Beiträge
- 125
- Points
- 8.092
- Level
- 60
- Downloads
- 5
- Uploads
- 2
-
07-16-2009, 09:55 AM #9874QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
i've already said that my psp crashes when i try to use that function, isn't there another one?
That epic dude.
-
07-16-2009, 11:38 AM #9875QJ Gamer Green
- Registriert seit
- Nov 2008
- Ort
- Portugal
- Beiträge
- 20
- Points
- 6.205
- Level
- 51
- Downloads
- 0
- Uploads
- 0
-
07-16-2009, 11:46 AM #9876QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- Perth, Scotland
- Beiträge
- 1.094
- Points
- 8.475
- Level
- 62
- Downloads
- 0
- Uploads
- 0
-
07-16-2009, 11:50 AM #9877QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
-
07-16-2009, 12:48 PM #9878QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
07-16-2009, 01:00 PM #9879QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
wow, i feel :humped:
what if i want to create a ms browser? i know that in Lua, you have to use the table.getn function...That epic dude.
-
07-16-2009, 02:22 PM #9880QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
07-16-2009, 02:56 PM #9881QJ Gamer Green
- Registriert seit
- Nov 2008
- Ort
- Portugal
- Beiträge
- 20
- Points
- 6.205
- Level
- 51
- Downloads
- 0
- Uploads
- 0
Ok I got it working.. Had to make it with 2 files. Thanks for your help anyway. Here's the code.
Code:FILE *fg, *fn; int i=0,len_string; char SrchText[]="abc"; char RplcText[]="acb\n456"; char tmp[20]; fg=fopen("test.txt","a+"); fn=fopen("test1.txt","w"); rewind(fg); if(fg==NULL) { printf("Error openning the file."); exit(0); } len_string=strlen(SrchText); while(!feof(fg)) { for(i=0;i<len_string;i++) temp[i]=fgetc(fg); if(strcmp(SrchText, temp) == 0) fprintf(fn, "%s", RplcText); else fprintf(fn, "%s", temp); } fclose(fp); fclose(fn);Geändert von bosshunter (07-16-2009 um 04:05 PM Uhr)
-
07-16-2009, 05:59 PM #9882Developer
- Registriert seit
- Jul 2008
- Ort
- Grand Rapids! MI
- Beiträge
- 125
- Points
- 8.092
- Level
- 60
- Downloads
- 5
- Uploads
- 2
^^^^^^^ in there you dont have the prx being called to for it to be started up/activated
The LoadStartModule(char *path) means Load and Start The Module(" At this exact location and here is the path to it ")
and also with that code you normally would have to have starting and ending brackets ( {starting }Ending) for the if and else functions .-.
Spoiler for LoadStartModule New Code:
what compiler are you using cause it should have given you an error saying it was expecting a '}' before the 'else' statement
-
07-16-2009, 06:34 PM #9883QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been
-
07-17-2009, 07:39 AM #9884QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
don't you think I know how to use that function?? I use
but it just doesn't wanna work. even when i compile the sample that comes with the PSPSDK. maybe it's the compiler? i'm using minPSPwCode:LoadStartModule("ms0:/module.prx");That epic dude.
-
07-17-2009, 10:33 AM #9885QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- Perth, Scotland
- Beiträge
- 1.094
- Points
- 8.475
- Level
- 62
- Downloads
- 0
- Uploads
- 0
-
07-18-2009, 04:31 PM #9886QJ Gamer Green
- Registriert seit
- May 2008
- Beiträge
- 96
- Points
- 3.008
- Level
- 33
- Downloads
- 0
- Uploads
- 0
-
07-18-2009, 05:48 PM #9887Developer
- Registriert seit
- Jul 2008
- Ort
- Grand Rapids! MI
- Beiträge
- 125
- Points
- 8.092
- Level
- 60
- Downloads
- 5
- Uploads
- 2
-
07-27-2009, 01:51 PM #9888QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
Okay, new question. I'm trying to make a prx that will print with intraFont and blit an image into the XMB. Am I allowed to use libs in kernel PRXs ?
That epic dude.
-
07-27-2009, 05:47 PM #9889xMod.
- Registriert seit
- Oct 2008
- Ort
- Melbourne, Australia
- Beiträge
- 675
- Points
- 4.576
- Level
- 43
- My Mood
-
- Downloads
- 0
- Uploads
- 0
look at blit.c examples included in intraFont and the sdk samples
-
07-28-2009, 04:44 AM #9890QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
where do I get the blit.c file from ?
EDIT:
I've read that VSHBlitter helps me with blitting images into the XMB. But I can't seem to find a download link. Does anyone know where it can be found ?Geändert von mootjeuh (07-28-2009 um 05:14 AM Uhr)
That epic dude.
-
07-28-2009, 10:12 AM #9891QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been
-
07-28-2009, 10:36 AM #9892QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
I've been google-ing it since yesterday but without any luck. The link given here doesn't even work.
That epic dude.
-
07-28-2009, 10:46 AM #9893Developer
- Registriert seit
- Jul 2008
- Ort
- Grand Rapids! MI
- Beiträge
- 125
- Points
- 8.092
- Level
- 60
- Downloads
- 5
- Uploads
- 2
-
07-30-2009, 02:43 AM #9894
Achievements:
- Registriert seit
- Jul 2009
- Beiträge
- 3
- Points
- 1.617
- Level
- 23
- Downloads
- 0
- Uploads
- 0
drawing pixels
does anyone know of how to simply draw pixels in PSPSDK?
I just need to create a simple function like drawpx(x,y,r,g,b)
thanks
-
07-30-2009, 02:49 AM #9895xMod.
- Registriert seit
- Oct 2008
- Ort
- Melbourne, Australia
- Beiträge
- 675
- Points
- 4.576
- Level
- 43
- My Mood
-
- Downloads
- 0
- Uploads
- 0
pspgu, check the sdk samples
-
07-30-2009, 04:15 AM #9896
Achievements:
- Registriert seit
- Jul 2009
- Beiträge
- 3
- Points
- 1.617
- Level
- 23
- Downloads
- 0
- Uploads
- 0
???
alright, I've have been looking through them for the last half hour and can't find anything useful. can I have a hint? :)
-
07-30-2009, 08:09 AM #9897
Achievements:
- Registriert seit
- Jul 2009
- Beiträge
- 3
- Points
- 1.617
- Level
- 23
- Downloads
- 0
- Uploads
- 0
could you atleast give me the function name? :Argh:
-
07-30-2009, 09:54 AM #9898QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
logan, it's not just a function, you need to setup the GU drawing buffer, than set it to ortho(or use GU_TRANSFORM_2D(been a while don't remeber if that's correct)), than draw with GU_POINTS(i believe it's GU_POINTS), it's quite simple, just take some time to look around, alternatively, you could use oslib(or any of the other graphic api's) if you don't feel like learning how to setup the gu for drawing.
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been
-
07-30-2009, 11:53 AM #9899QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
since I still haven't figured out on how to blit images into the XMB, does someone know how to draw a filled rectangle to the screen? I mean, without using any libs.
That epic dude.
-
08-09-2009, 06:52 AM #9900Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
ok, im dabbling in C a bit more now and i have a bit of a silly problem. I want to check if there is a UMD disk in the drive on my slim psp but the function always returns that there is no matter what.
here is my code:
im running in user mode dont know if that affects anything? although i would think that the umd would be in user mode. oh and yes i have included the lib in my makefile.Code:#include <oslib/oslib.h> #include <pspumd.h> PSP_MODULE_INFO("Testing", 0, 1, 0); PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU); int main() { oslInit(0); oslInitGfx(OSL_PF_8888, 1); oslInitConsole(); while (!osl_quit) { oslStartDrawing(); oslCls(); oslReadKeys(); int umdDetectedVariable; umdDetectedVariable = sceUmdCheckMedium(); if (umdDetectedVariable == 0) { oslPrintf_xy(20, 240, "No UMD disc is inserted."); } else { oslPrintf_xy(20, 240, "UMD disc is inserted."); } if (osl_keys->held.hold) { oslPrintf_xy(20, 250, "Hold Activated!"); } if (osl_keys->pressed.start) { break; } oslEndDrawing(); oslSyncFrame(); } oslEndGfx(); oslQuit(); return 0; }
Thanks for any help, its probably something simple.------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum