Seite 203 von 340 ErsteErste ... 103 153 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 253 303 ... LetzteLetzte
Zeige Ergebnis 6.061 bis 6.090 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; Zitat von Auraomega I checked on there about 5 minutes before posting here, the only tutorial I could find was ...

  
  1. #6061
    QJ Gamer Green
    Points: 4.824, Level: 44
    Level completed: 37%, Points required for next Level: 126
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    317
    Points
    4.824
    Level
    44
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega

    I checked on there about 5 minutes before posting here, the only tutorial I could find was for loading it all into RAM, which isn't really suitable.
    why not? you can free the memory it takes up after its done playing.


    Current releases:
    Icon Action Replacer v1.5- latest release
    Current projects:
    PSP C++ IDE - Currently v1.6
    RPG Paradise - Latest version at my website

  2. #6062
    It's good to be free...
    Points: 10.420, Level: 67
    Level completed: 93%, Points required for next Level: 30
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    2.440
    Points
    10.420
    Level
    67
    Downloads
    0
    Uploads
    0
    pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ

  3. #6063
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von pspballer07
    why not? you can free the memory it takes up after its done playing.
    *Sigh*... because loading mp3s into RAM takes up a lot of space, and I have songs that are almost 100mb big (over an hour long) which simply won't fit into the PSPs memory.

    Zitat Zitat von Archaemic
    Mess around with that source.
    Thanks, I'll take a look :)

    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  4. #6064
    Heroes never die
    Points: 8.645, Level: 62
    Level completed: 65%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    ...........
    Beiträge
    1.323
    Points
    8.645
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    what about , dam whats the name again , alright the thing that sony uses to play big mp3files , youresam made one too I guess

  5. #6065
    QJ Gamer Blue
    Points: 4.031, Level: 40
    Level completed: 41%, Points required for next Level: 119
    Overall activity: 91,0%

    Registriert seit
    Feb 2007
    Ort
    Florida
    Beiträge
    214
    Points
    4.031
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega

    I wasn't sure if you wanted it so that it registers a 1 ONLY when a button is being pressed or not. If you want a 1 to register only when a button is pressed, then when nothing is pressed the negative kicks in, and allows the code under it to run. As I said, only use if you need it


    -Aura
    Acutally, that's exactly what I need. Thanks a bunch. :)

  6. #6066
    QJ Gamer Green
    Points: 4.824, Level: 44
    Level completed: 37%, Points required for next Level: 126
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    317
    Points
    4.824
    Level
    44
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega
    *Sigh*... because loading mp3s into RAM takes up a lot of space, and I have songs that are almost 100mb big (over an hour long) which simply won't fit into the PSPs memory.
    dang dude, what would you need a 100 mb song for?
    Current releases:
    Icon Action Replacer v1.5- latest release
    Current projects:
    PSP C++ IDE - Currently v1.6
    RPG Paradise - Latest version at my website

  7. #6067
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von pspballer07
    dang dude, what would you need a 100 mb song for?
    Lol, I just like VNV Nation (a little too much), the song is 94.4mb big... and its not the only one (I have a few others tending towards that sort of size).

    A lot of my music is over 16mb big anyway (16mb being the biggest you can get in a partition if I remember rightly?), so this is more just so I can play all my music how I want, not with Sony's crappy one that only works in the XMB :Argh:

    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  8. #6068
    Heroes never die
    Points: 8.645, Level: 62
    Level completed: 65%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    ...........
    Beiträge
    1.323
    Points
    8.645
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    you dont need to copy the complete file to memory

  9. #6069
    QJ Gamer Green
    Points: 4.824, Level: 44
    Level completed: 37%, Points required for next Level: 126
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    317
    Points
    4.824
    Level
    44
    Downloads
    0
    Uploads
    0

    Standard

    oh i see, but I think the mp3player.c from the psp-programming tuts streams it. Did u try it?
    Current releases:
    Icon Action Replacer v1.5- latest release
    Current projects:
    PSP C++ IDE - Currently v1.6
    RPG Paradise - Latest version at my website

  10. #6070
    Heroes never die
    Points: 8.645, Level: 62
    Level completed: 65%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    ...........
    Beiträge
    1.323
    Points
    8.645
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    streaming that was the word:):):)

  11. #6071
    Points: 3.139, Level: 34
    Level completed: 60%, Points required for next Level: 61
    Overall activity: 39,0%

    Registriert seit
    Aug 2007
    Beiträge
    31
    Points
    3.139
    Level
    34
    Downloads
    0
    Uploads
    0

    Standard

    No I'm pretty sure the mp3 player library given in the psp-programming tutes loads the entire file into memory.

    After a bit of a seach I came up with this thread at ps2dev.org: http://forums.ps2dev.org/viewtopic.php?t=5089.

    Specifically PeterM's code half way down the page.

    It seems others have also had trouble with this, the solution is to buffer the file reading, filling the buffer from the memory stick while the at the same time playing the stream. The code seems pretty easy to follow.
    He does note that it is a bit slow however.

  12. #6072
    Points: 11.498, Level: 70
    Level completed: 62%, Points required for next Level: 152
    Overall activity: 50,0%

    Registriert seit
    Dec 2005
    Ort
    LBC
    Beiträge
    516
    Points
    11.498
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega
    Code:
    printf("Hello");
    printf("Hi");
    would be even simplier, but I doubt anyone is going to want their program to just say
    Hello
    Hi
    The string is going to have different values store in it no doubt, which makes both of the above useless.

    -Aura
    what i was trying to get across is there is no need for having a buffer at all.. you can just do

    printf("%s %02f %s", "a string", 2.5f, "another string"); or whatever you want...

    printf("%s %02d %s", myCharVariable1, myIntVariable, myCharVariable2); ....

    printf("Some Text %s My Int %02d More Text %s", myCharVariable1, myIntVariable, myCharVariable2);

    etc etc

    of course nobody will have their program just say "hello hi" that's retarded of you to think that is what I was implying.

    now of course if you want to make your program twice as long and have to fill a buffer everytime you want to printf something you can always do as mentioned above and do

    strcpy(buffer, "Some text");
    printf("%s", buffer);

    everytime you want something printed...

    but then how will you get other variables in there like floats or ints?
    you can't with strcpy at least not without casting.. at least as far as I know everytime I try strcpy(buffer, "%s %d", myCharVariable, myIntVariable) I get massive errors ;) (of course I know that doesn't work)

    so in the end you would be left with

    strcpy(buffer, "some text");
    printf("%s %02d", buffer, myIntVariable);

    which.. well.. nevermind just do what you want... it all works.

  13. #6073
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    @psp_jono:
    Cheers, the more source code the merrier

    Zitat Zitat von califrag
    what i was trying to get across is there is no need for having a buffer at all.. you can just do

    printf("%s %02f %s", "a string", 2.5f, "another string"); or whatever you want...

    printf("%s %02d %s", myCharVariable1, myIntVariable, myCharVariable2); ....

    printf("Some Text %s My Int %02d More Text %s", myCharVariable1, myIntVariable, myCharVariable2);

    etc etc

    of course nobody will have their program just say "hello hi" that's retarded of you to think that is what I was implying.
    I never thought you were implying that, but, if you do what you've done there, you will ALWAYS have the same text, because its not in a variable. All the other peices of code shown allow use of loops, but if you looped any code written how you've done it, there will be no variation because you just hardcode the text you want.

    Your way would work fine, but its big and bulky, and taking up a lot of pointless space that could just be simplified a LOT by using sprintf.

    As for the
    Code:
    printf("%s %02d %s", myCharVariable1, myIntVariable, myCharVariable2);
    umm... how do you expected to get a variable into myCharVariable without using sprintf, or hell, without even using a buffer? Not going to happen.
    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  14. #6074
    QJ Gamer Green
    Points: 11.800, Level: 71
    Level completed: 38%, Points required for next Level: 250
    Overall activity: 0%

    Registriert seit
    Jul 2006
    Ort
    Middle Europe
    Beiträge
    1.281
    Points
    11.800
    Level
    71
    Downloads
    0
    Uploads
    0

    Standard

    char myCharVar[9] = "hello all"

    printf("%s",myCharVar);

    this would work right? and i didnt use sprintf

  15. #6075
    Points: 3.139, Level: 34
    Level completed: 60%, Points required for next Level: 61
    Overall activity: 39,0%

    Registriert seit
    Aug 2007
    Beiträge
    31
    Points
    3.139
    Level
    34
    Downloads
    0
    Uploads
    0

    Standard

    char myCharVar[9] = "hello all"

    printf("%s",myCharVar);

    this would work right? and i didnt use sprintf
    Actually no, it would fail because the string is too long for the buffer variable. The string constant "hello all" is actually 10 characters long because of the termenating null character at the end.
    All strings should have a terminating null character at the end.

    Correct code:

    Code:
    char myCharVar[10] = "hello all";
    
    printf("%s",myCharVar);
    :)

  16. #6076
    QJ Gamer Bronze
    Points: 5.402, Level: 47
    Level completed: 26%, Points required for next Level: 148
    Overall activity: 0%

    Registriert seit
    Apr 2007
    Beiträge
    468
    Points
    5.402
    Level
    47
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von myschoo
    char myCharVar[9] = "hello all"

    printf("%s",myCharVar);

    this would work right? and i didnt use sprintf
    yeah jono's right. the compiler automatically adds the '\0' null terminator to a string literal therefore 9 characters isn't enough to store your string. just let the compiler work out the size of myCharVar

    char myCharVar[] = "hello all";

  17. #6077
    Heroes never die
    Points: 8.645, Level: 62
    Level completed: 65%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    ...........
    Beiträge
    1.323
    Points
    8.645
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    char hallo[5] = "hallo";
    works 100% fine


    before u say , i say BS
    look at this from cprograming.com

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      int x;
      int y;
      int array[8][8]; // Declares an array like a chessboard
      
      for ( x = 0; x < 8; x++ ) {
        for ( y = 0; y < 8; y++ )
          array[x][y] = x * y; // Set each element to a value
      }
      cout<<"Array Indices:\n";
      for ( x = 0; x < 8;x++ ) {
        for ( y = 0; y < 8; y++ )
          cout<<"["<<x<<"]["<<y<<"]="<< array[x][y] <<" ";
        cout<<"\n";
      }
      cin.get();
    }

  18. #6078
    QJ Gamer Bronze
    Points: 5.402, Level: 47
    Level completed: 26%, Points required for next Level: 148
    Overall activity: 0%

    Registriert seit
    Apr 2007
    Beiträge
    468
    Points
    5.402
    Level
    47
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von hallo007
    char hallo[5] = "hallo";
    works 100% fine


    before u say , i say BS
    look at this from cprograming.com

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      int x;
      int y;
      int array[8][8]; // Declares an array like a chessboard
      
      for ( x = 0; x < 8; x++ ) {
        for ( y = 0; y < 8; y++ )
          array[x][y] = x * y; // Set each element to a value
      }
      cout<<"Array Indices:\n";
      for ( x = 0; x < 8;x++ ) {
        for ( y = 0; y < 8; y++ )
          cout<<"["<<x<<"]["<<y<<"]="<< array[x][y] <<" ";
        cout<<"\n";
      }
      cin.get();
    }
    i'm not a c++ programmer so i'm not qualified to comment on that code but i fail to see what a 2 dimensional array of integers has to do with the point i was making about string literals.

    maybe char hallo[5] = "hallo"; does work but that doesn't stop it being wrong

  19. #6079
    It's good to be free...
    Points: 10.420, Level: 67
    Level completed: 93%, Points required for next Level: 30
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    2.440
    Points
    10.420
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    No, char hallo[5] = "hallo" will not work. "hallo" is six characters long. The double quotes alway add a null byte at the end. Therefore, even though it appears to be five characters long, it's really six.
    pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ

  20. #6080
    QJ Gamer Bronze
    Points: 5.402, Level: 47
    Level completed: 26%, Points required for next Level: 148
    Overall activity: 0%

    Registriert seit
    Apr 2007
    Beiträge
    468
    Points
    5.402
    Level
    47
    Downloads
    0
    Uploads
    0

    Standard

    i've just seen the point your making, hallo007 (the bolded bit)

    when you declare int x[8]; it stores its values like this - x[0] for the first integer of the array and x[7] for the last. thats why the second expression of the for loop is x < 8

  21. #6081
    Heroes never die
    Points: 8.645, Level: 62
    Level completed: 65%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    ...........
    Beiträge
    1.323
    Points
    8.645
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    I see my mistak , I mostly use array pointers , they dont have it

  22. #6082
    QJ Gamer Green
    Points: 5.712, Level: 48
    Level completed: 81%, Points required for next Level: 38
    Overall activity: 0%

    Registriert seit
    Jul 2006
    Ort
    USA SC/NC
    Beiträge
    699
    Points
    5.712
    Level
    48
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von hallo007
    I see my mistak , I mostly use array pointers , they dont have it
    eh? Assuming you are talking about a C string, a null byte is appended to the end of it...

    When you use double quotes, a null byte is appended to the end of the array.
    [CODE]Random Facts:
    irc://irc.malloc.us #wtf #**********
    [/CODE]

    [SIZE="6"][FONT="Century Gothic"][COLOR="Blue"][URL="http://forums.**********.net"]http://forums.**********.net[/URL][/COLOR][/FONT][/SIZE]

  23. #6083
    QJ Gamer Blue
    Points: 3.795, Level: 38
    Level completed: 97%, Points required for next Level: 5
    Overall activity: 27,0%

    Registriert seit
    Jul 2007
    Beiträge
    296
    Points
    3.795
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Moca
    eh? Assuming you are talking about a C string, a null byte is appended to the end of it...

    When you use double quotes, a null byte is appended to the end of the array.
    :o Yay! I spotted a moca!

  24. #6084
    QJ Gamer Blue
    Points: 4.031, Level: 40
    Level completed: 41%, Points required for next Level: 119
    Overall activity: 91,0%

    Registriert seit
    Feb 2007
    Ort
    Florida
    Beiträge
    214
    Points
    4.031
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Is there anything you guys I could suggest for me to be able to save a homebrew game with? (Besides a .txt?)

  25. #6085
    lol
    Points: 20.859, Level: 91
    Level completed: 2%, Points required for next Level: 491
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    Whittier, CA
    Beiträge
    5.791
    Points
    20.859
    Level
    91
    Downloads
    0
    Uploads
    0

    Standard

    .sav file

  26. #6086
    QJ Gamer Green
    Points: 4.824, Level: 44
    Level completed: 37%, Points required for next Level: 126
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    317
    Points
    4.824
    Level
    44
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von MrChaos
    Is there anything you guys I could suggest for me to be able to save a homebrew game with? (Besides a .txt?)
    *.anythingyouwant

    then u could have ur own save file format that stores all the vars
    Current releases:
    Icon Action Replacer v1.5- latest release
    Current projects:
    PSP C++ IDE - Currently v1.6
    RPG Paradise - Latest version at my website

  27. #6087
    QJ Gamer Blue
    Points: 3.795, Level: 38
    Level completed: 97%, Points required for next Level: 5
    Overall activity: 27,0%

    Registriert seit
    Jul 2007
    Beiträge
    296
    Points
    3.795
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    Just do something similar to,
    Code:
    typedef struct _GAME_STATE
    {
    	int blah1;
    	int blah2;
    
    	char name[20];
    	char lala;
    
    	int level;
    	int start;
    	int health;
    } SGameState;
    
    int saveGameState(const char* path, SGameState* gs)
    {
    	FILE* pFile = fopen(path, "rb");
    	fwrite(gs, sizeof(SGameState, 1, pFile);
    	fclose(pFile);
    	return 1;
    }
    
    int loadGameState(const char* path, SGameState* gs)
    {
    	FILE* pFile = fopen(path, "rb");
    	fread(gs, sizeof(SGameState), 1, pFile);
    	fclose(pFile);
    	return 1;
    }
    Then just pick a convenient extension, like '.sav' as Anti has said.

    (With error checking, of course.)

  28. #6088
    Points: 3.139, Level: 34
    Level completed: 60%, Points required for next Level: 61
    Overall activity: 39,0%

    Registriert seit
    Aug 2007
    Beiträge
    31
    Points
    3.139
    Level
    34
    Downloads
    0
    Uploads
    0

    Standard

    I see my mistak , I mostly use array pointers , they dont have it
    I'm not sure what this post actually means but I'm sorry if I didn't explain the problem well. As you know an array is a collection of common structures stored in sequential memory.

    The string "hello all" should actually be stored in sequential memory as:
    Code:
        [h] [e] [l] [l] [o] [ ] [a] [l] [l] [\0]
    rather than:
    Code:
        [h] [e] [l] [l] [o] [ ] [a] [l] [l]
    Where the square brackets are a single byte/char variable.

    As you can see the correct example requires the array to be 10 elements long rather than 9.

    While a string could be stored in memory without the null char, it isn't a good idea. Many function rely on the null character to signify the end of a string, without it they would continue working past the end of the string reading or writing to random data, this could cause weird, hard to track bugs or complete crashes.

    Hopefully this helps :)

    char hallo[5] = "hallo";
    works 100% fine
    I'm pretty sure that wont even compile.

    Originally Posted by MrChaos
    Is there anything you guys I could suggest for me to be able to save a homebrew game with? (Besides a .txt?)
    I'd go with a binary format like _dysfunctional's example. While easier to understand, text format save files are often too easy for people to edit in order to cheat. With binary you can make it harder to modify the variables that are important to cheaters. Especially those with little knowledge of programming.
    Geändert von psp_jono (08-15-2007 um 05:02 PM Uhr)

  29. #6089
    Points: 11.498, Level: 70
    Level completed: 62%, Points required for next Level: 152
    Overall activity: 50,0%

    Registriert seit
    Dec 2005
    Ort
    LBC
    Beiträge
    516
    Points
    11.498
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega
    @psp_jono:
    Cheers, the more source code the merrier


    I never thought you were implying that, but, if you do what you've done there, you will ALWAYS have the same text, because its not in a variable. All the other peices of code shown allow use of loops, but if you looped any code written how you've done it, there will be no variation because you just hardcode the text you want.

    Your way would work fine, but its big and bulky, and taking up a lot of pointless space that could just be simplified a LOT by using sprintf.

    As for the
    Code:
    printf("%s %02d %s", myCharVariable1, myIntVariable, myCharVariable2);
    umm... how do you expected to get a variable into myCharVariable without using sprintf, or hell, without even using a buffer? Not going to happen.
    -Aura
    I don't see how using "sprintf" and buffers can simplify this code:

    Code:
    printf("Sometext 2 Moretext");
    or

    Code:
    printf("%s %02d %s", myCharVariable1, myIntVariable, myCharVariable2);
    to:
    Code:
    char myCharVariable1[50], myCharVariable2[50]; int myIntVariable;
    sprintf(myCharVariable1, "Sometext");
    sprintf(myCharVariable2, "Moretext");
    myIntVariable = 2;
    sprintf(buffer, "%s %02d %s", myCharVariable1, myIntVariable, myCharVariable2);
    printf("%s", buffer);
    keep using sprintf's and buffers for everything and i will keep a minimalist approach. Thanks!
    Plus it all depends on what you are doing and whether the text is static or not, and if it is not static of course you will need to use sprintfs to initialize the variables with the data you need.
    Geändert von califrag (08-15-2007 um 05:11 PM Uhr)

  30. #6090
    It's good to be free...
    Points: 10.420, Level: 67
    Level completed: 93%, Points required for next Level: 30
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    2.440
    Points
    10.420
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    So many things wrong with both of those, I don't know where to begin @@
    pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ


 

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:14 PM Uhr.

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