Seite 330 von 340 ErsteErste ... 230 280 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 ... LetzteLetzte
Zeige Ergebnis 9.871 bis 9.900 von 10174

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 ...

  
  1. #9871
    QJ Gamer Green
    Points: 6.205, Level: 51
    Level completed: 28%, Points required for next Level: 145
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    Portugal
    Beiträge
    20
    Points
    6.205
    Level
    51
    Downloads
    0
    Uploads
    0

    Standard

    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);



  2. #9872
    QJ Gamer Bronze
    Points: 5.583, Level: 48
    Level completed: 17%, Points required for next Level: 167
    Overall activity: 0%

    Registriert seit
    May 2007
    Beiträge
    127
    Points
    5.583
    Level
    48
    Downloads
    0
    Uploads
    0

    Standard

    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)

  3. #9873
    Developer
    Points: 8.092, Level: 60
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Jul 2008
    Ort
    Grand Rapids! MI
    Beiträge
    125
    Points
    8.092
    Level
    60
    Downloads
    5
    Uploads
    2

    Standard

    Zitat Zitat von mootjeuh Beitrag anzeigen
    i don't get it. all i want to do is load a prx. i don't even know HOW to define what prx i want to load.
    you put LoadStartModule("ThePathT oThePRX/ThePrxNameHere.prx");
    and it should load it

  4. #9874
    QJ Gamer Gold
    Points: 13.372, Level: 75
    Level completed: 31%, Points required for next Level: 278
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    CAD
    Beiträge
    693
    Points
    13.372
    Level
    75
    Downloads
    19
    Uploads
    4

    Standard

    i've already said that my psp crashes when i try to use that function, isn't there another one?
    That epic dude.

  5. #9875
    QJ Gamer Green
    Points: 6.205, Level: 51
    Level completed: 28%, Points required for next Level: 145
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    Portugal
    Beiträge
    20
    Points
    6.205
    Level
    51
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von _df_ Beitrag anzeigen
    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.
    Is there any tutorial on how to do this?
    Can't find one with good examples..

  6. #9876
    QJ Gamer Silver
    Points: 8.475, Level: 62
    Level completed: 9%, Points required for next Level: 275
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Perth, Scotland
    Beiträge
    1.094
    Points
    8.475
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von mootjeuh Beitrag anzeigen
    i've already said that my psp crashes when i try to use that function, isn't there another one?
    What error?

  7. #9877
    QJ Gamer Gold
    Points: 13.372, Level: 75
    Level completed: 31%, Points required for next Level: 278
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    CAD
    Beiträge
    693
    Points
    13.372
    Level
    75
    Downloads
    19
    Uploads
    4

    Standard

    Zitat Zitat von Davee Beitrag anzeigen
    What error?
    it just crashes, no error. although when i run my prx through iR Shell, it works just fine.




    what are the table functions in C/C++ ?
    for example, what's table.getn (lua) in C/C++ ?
    That epic dude.

  8. #9878
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von mootjeuh Beitrag anzeigen
    what are the table functions in C/C++ ?
    for example, what's table.getn (lua) in C/C++ ?
    There are no tables in C or C++.

  9. #9879
    QJ Gamer Gold
    Points: 13.372, Level: 75
    Level completed: 31%, Points required for next Level: 278
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    CAD
    Beiträge
    693
    Points
    13.372
    Level
    75
    Downloads
    19
    Uploads
    4

    Standard

    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.

  10. #9880
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von mootjeuh Beitrag anzeigen
    what if i want to create a ms browser? i know that in Lua, you have to use the table.getn function...
    You use C or C++ data structures and types. The general logic will be same.

  11. #9881
    QJ Gamer Green
    Points: 6.205, Level: 51
    Level completed: 28%, Points required for next Level: 145
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    Portugal
    Beiträge
    20
    Points
    6.205
    Level
    51
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von _df_ Beitrag anzeigen
    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.
    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)

  12. #9882
    Developer
    Points: 8.092, Level: 60
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Jul 2008
    Ort
    Grand Rapids! MI
    Beiträge
    125
    Points
    8.092
    Level
    60
    Downloads
    5
    Uploads
    2

    Standard

    Zitat Zitat von mootjeuh Beitrag anzeigen
    Spoiler for LoadStartModule:

    int LoadStartModule(char *path)
    {
    u32 loadResult;
    u32 startResult;
    int status;

    loadResult = sceKernelLoadModule(path, 0, NULL);
    if (loadResult & 0x80000000)
    return -1;
    else
    startResult =
    sceKernelStartModule(load Result, 0, NULL, &status, NULL);

    if (loadResult != startResult)
    return -2;

    return 0;
    }
    ^^^^^^^ 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:

    int LoadStartModule(char *path)
    {
    u32 loadResult;
    u32 startResult;
    int status;

    loadResult = sceKernelLoadModule(path, 0, NULL);
    if (loadResult & 0x80000000)
    {
    return -1;
    }
    else
    {
    startResult = sceKernelStartModule(load Result, 0, NULL, &status, NULL);
    }

    if (loadResult != startResult)
    {
    return -2;
    }
    return 0;
    }


    what compiler are you using cause it should have given you an error saying it was expecting a '}' before the 'else' statement

  13. #9883
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    Zitat Zitat von lilmnm Beitrag anzeigen
    ^^^^^^^ 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:

    int LoadStartModule(char *path)
    {
    u32 loadResult;
    u32 startResult;
    int status;

    loadResult = sceKernelLoadModule(path, 0, NULL);
    if (loadResult & 0x80000000)
    {
    return -1;
    }
    else
    {
    startResult = sceKernelStartModule(load Result, 0, NULL, &status, NULL);
    }

    if (loadResult != startResult)
    {
    return -2;
    }
    return 0;
    }


    what compiler are you using cause it should have given you an error saying it was expecting a '}' before the 'else' statement
    no, what he did is perfectly legal:

    Code:
    if(a) 
       b=a;
    //^^legal
    
    if(a) 
       b=a; 
       a=b; 
    //^^^not legal(well it is, but a=b isn't incompassed inside the if statement's field of scope)
    
    if(a){
       b=a;
       a=b;
    }
    //^^legal
    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

  14. #9884
    QJ Gamer Gold
    Points: 13.372, Level: 75
    Level completed: 31%, Points required for next Level: 278
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    CAD
    Beiträge
    693
    Points
    13.372
    Level
    75
    Downloads
    19
    Uploads
    4

    Standard

    don't you think I know how to use that function?? I use
    Code:
    LoadStartModule("ms0:/module.prx");
    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 minPSPw
    That epic dude.

  15. #9885
    QJ Gamer Silver
    Points: 8.475, Level: 62
    Level completed: 9%, Points required for next Level: 275
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Perth, Scotland
    Beiträge
    1.094
    Points
    8.475
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von mootjeuh Beitrag anzeigen
    it just crashes, no error. although when i run my prx through iR Shell, it works just fine.




    what are the table functions in C/C++ ?
    for example, what's table.getn (lua) in C/C++ ?
    Use a debugger like PSPLink then.

  16. #9886
    QJ Gamer Green
    Points: 3.008, Level: 33
    Level completed: 72%, Points required for next Level: 42
    Overall activity: 0%

    Registriert seit
    May 2008
    Beiträge
    96
    Points
    3.008
    Level
    33
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von FaT3oYCG Beitrag anzeigen
    google = MinPSPW
    and then?

  17. #9887
    Developer
    Points: 8.092, Level: 60
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Jul 2008
    Ort
    Grand Rapids! MI
    Beiträge
    125
    Points
    8.092
    Level
    60
    Downloads
    5
    Uploads
    2

    Standard

    Zitat Zitat von mootjeuh Beitrag anzeigen
    don't you think I know how to use that function?? I use
    Code:
    LoadStartModule("ms0:/module.prx");
    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 minPSPw
    that may be it i use cygwin on my desktop and ubuntu on my laptop but in that past i used CSP 3.1, but i have never heard of that minPSPw .-.

  18. #9888
    QJ Gamer Gold
    Points: 13.372, Level: 75
    Level completed: 31%, Points required for next Level: 278
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    CAD
    Beiträge
    693
    Points
    13.372
    Level
    75
    Downloads
    19
    Uploads
    4

    Standard

    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.

  19. #9889
    xMod.
    Points: 4.576, Level: 43
    Level completed: 13%, Points required for next Level: 174
    Overall activity: 0%

    Registriert seit
    Oct 2008
    Ort
    Melbourne, Australia
    Beiträge
    675
    Points
    4.576
    Level
    43
    My Mood
    Daring
    Downloads
    0
    Uploads
    0

    Standard

    look at blit.c examples included in intraFont and the sdk samples
    I hate those monkeys ZOMG!
    -~Slasher~-
    http://i18.tinypic.com/4m848p5.gif

  20. #9890
    QJ Gamer Gold
    Points: 13.372, Level: 75
    Level completed: 31%, Points required for next Level: 278
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    CAD
    Beiträge
    693
    Points
    13.372
    Level
    75
    Downloads
    19
    Uploads
    4

    Standard

    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.

  21. #9891
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    Zitat Zitat von slasher2661996 Beitrag anzeigen
    look at blit.c examples included in intraFont and the sdk samples
    as for the vshblitter, idk, google's your best bet
    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

  22. #9892
    QJ Gamer Gold
    Points: 13.372, Level: 75
    Level completed: 31%, Points required for next Level: 278
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    CAD
    Beiträge
    693
    Points
    13.372
    Level
    75
    Downloads
    19
    Uploads
    4

    Standard

    I've been google-ing it since yesterday but without any luck. The link given here doesn't even work.
    That epic dude.

  23. #9893
    Developer
    Points: 8.092, Level: 60
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Jul 2008
    Ort
    Grand Rapids! MI
    Beiträge
    125
    Points
    8.092
    Level
    60
    Downloads
    5
    Uploads
    2

    Standard

    Zitat Zitat von mootjeuh Beitrag anzeigen
    I've been google-ing it since yesterday but without any luck. The link given here doesn't even work.
    i think i have seen that on this forum try searching i know its here somewhere
    Geändert von lilmnm (07-28-2009 um 10:56 AM Uhr)

  24. #9894
    Points: 1.617, Level: 23
    Level completed: 17%, Points required for next Level: 83
    Overall activity: 0%
    Achievements:
    First 1000 Experience Points

    Registriert seit
    Jul 2009
    Beiträge
    3
    Points
    1.617
    Level
    23
    Downloads
    0
    Uploads
    0

    Standard 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

  25. #9895
    xMod.
    Points: 4.576, Level: 43
    Level completed: 13%, Points required for next Level: 174
    Overall activity: 0%

    Registriert seit
    Oct 2008
    Ort
    Melbourne, Australia
    Beiträge
    675
    Points
    4.576
    Level
    43
    My Mood
    Daring
    Downloads
    0
    Uploads
    0

    Standard

    pspgu, check the sdk samples
    I hate those monkeys ZOMG!
    -~Slasher~-
    http://i18.tinypic.com/4m848p5.gif

  26. #9896
    Points: 1.617, Level: 23
    Level completed: 17%, Points required for next Level: 83
    Overall activity: 0%
    Achievements:
    First 1000 Experience Points

    Registriert seit
    Jul 2009
    Beiträge
    3
    Points
    1.617
    Level
    23
    Downloads
    0
    Uploads
    0

    Standard ???

    alright, I've have been looking through them for the last half hour and can't find anything useful. can I have a hint? :)

  27. #9897
    Points: 1.617, Level: 23
    Level completed: 17%, Points required for next Level: 83
    Overall activity: 0%
    Achievements:
    First 1000 Experience Points

    Registriert seit
    Jul 2009
    Beiträge
    3
    Points
    1.617
    Level
    23
    Downloads
    0
    Uploads
    0

    Standard

    could you atleast give me the function name? :Argh:

  28. #9898
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    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

  29. #9899
    QJ Gamer Gold
    Points: 13.372, Level: 75
    Level completed: 31%, Points required for next Level: 278
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    CAD
    Beiträge
    693
    Points
    13.372
    Level
    75
    Downloads
    19
    Uploads
    4

    Standard

    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.

  30. #9900
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    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:

    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;
    }
    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.

    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).


 

Tags for this Thread

Forumregeln

  • Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
  • Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
  • Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
  • Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
  •  





Alle Zeitangaben in WEZ -8. Es ist jetzt 09:15 PM Uhr.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © , Caputo Media, LLC. All Rights Reserved. Cluster .