Seite 206 von 340 ErsteErste ... 106 156 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 256 306 ... LetzteLetzte
Zeige Ergebnis 6.151 bis 6.180 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; Maybe have a go at the psp-programming.com 'getting started' tutorials, they go through the basics, you can then build from ...

  
  1. #6151
    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

    Maybe have a go at the psp-programming.com 'getting started' tutorials, they go through the basics, you can then build from there.



  2. #6152
    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 MaTiAz
    uh, isn't it completely the opposite?
    try it. I think thats right.
    Current releases:
    Icon Action Replacer v1.5- latest release
    Current projects:
    PSP C++ IDE - Currently v1.6
    RPG Paradise - Latest version at my website

  3. #6153
    QJ Gamer Silver
    Points: 7.385, Level: 57
    Level completed: 18%, Points required for next Level: 165
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Finland
    Beiträge
    752
    Points
    7.385
    Level
    57
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von pspballer07
    try it. I think thats right.
    I've used paths like ms0:/PSP/PHOTO/ many times and they've all worked with only one slash. I've never bothered trying to use backslashes, but it's definitely the other way around when you're sprintf'ing paths (like ms0:/ requires no escape characters but ms0:\ requires another \).
    wheeee =:D

  4. #6154
    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

    i always use / and it works perfect

  5. #6155
    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

    a file got always hexadecimales , like 0xFF , that a character cant handle

    but i need to make a if statement like this

    //read data of file x to y
    //if y[0x08] == 0xFF

    with wich type do I do that?

  6. #6156
    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 MaTiAz
    I've used paths like ms0:/PSP/PHOTO/ many times and they've all worked with only one slash. I've never bothered trying to use backslashes, but it's definitely the other way around when you're sprintf'ing paths (like ms0:/ requires no escape characters but ms0:\ requires another \).
    ok well i'll fix my post
    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. #6157
    QJ Gamer Green
    Points: 5.795, Level: 49
    Level completed: 23%, Points required for next Level: 155
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Cape Town, South Africa
    Beiträge
    714
    Points
    5.795
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    Only a backwards OS (i.e. Windows) uses backslashes :) . Just use forward slashes on the PSP.

  8. #6158
    QJ Gamer Gold
    Points: 14.678, Level: 78
    Level completed: 57%, Points required for next Level: 172
    Overall activity: 0%

    Registriert seit
    Nov 2006
    Beiträge
    1.523
    Points
    14.678
    Level
    78
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von hallo007
    a file got always hexadecimales , like 0xFF , that a character cant handle

    but i need to make a if statement like this

    //read data of file x to y
    //if y[0x08] == 0xFF

    with wich type do I do that?
    long int.

  9. #6159
    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
    a file got always hexadecimales , like 0xFF , that a character cant handle
    but i need to make a if statement like this
    //read data of file x to y
    //if y[0x08] == 0xFF

    with wich type do I do that?
    Going by those two things I highlighted in bold, I assume you are reading 1 byte at a time. In that case, use type char. a character CAN handle 0xFF without losing any data. :\ 0xFF is the highest a char can handle.
    Zitat Zitat von Mr305
    long int.
    Why is that? If he is checking 1 byte at a time, then an unsigned char would be sufficient.
    [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]

  10. #6160
    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

    Say I make a file called global.c and store all my global variables inside it, could I then in the makefile type global.o to allow all my other files access to these globals? I've not used globals often before, and I don't feel like messing up any code just to test this theory.

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

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

  11. #6161
    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
    Say I make a file called global.c and store all my global variables inside it, could I then in the makefile type global.o to allow all my other files access to these globals? I've not used globals often before, and I don't feel like messing up any code just to test this theory.

    Thanks.
    -Aura
    what i did for global vars for all .c files to use is did this:

    global.h
    Code:
    typedef struct Global
    {
          //put all global vars here
         float Varf;
    };
    
    extern Global global;
    global.c
    Code:
    #include "global.h"
    
    Global global;
    which u can use it like this:

    Code:
    global.Varf = 1.0f;
    then u would add global.o to ur makefile
    Current releases:
    Icon Action Replacer v1.5- latest release
    Current projects:
    PSP C++ IDE - Currently v1.6
    RPG Paradise - Latest version at my website

  12. #6162
    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

    Ah cheers, this will certainly save having to use globals all in the same file (which is what scared me away from doing it in the past).

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

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

  13. #6163
    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

    Noobish question time:

    I'm using printTextScreen, and I want to be able to print the value of a function on the screen.

    (Ex: if LinkLevel = 1, I want to display this on the screen: Level: 1).
    I couldn't figure out how to do this, and I even looked at some tutorials...Help?

    Heres what I tried:

    printTextScreen(3, 3, "Level: %LinkLevel", RGB(255, 255, 255));
    And obviously...That's not how you do it.
    Help?

  14. #6164
    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 MrChaos
    Noobish question time:

    I'm using printTextScreen, and I want to be able to print the value of a function on the screen.

    (Ex: if LinkLevel = 1, I want to display this on the screen: Level: 1).
    I couldn't figure out how to do this, and I even looked at some tutorials...Help?

    Heres what I tried:

    printTextScreen(3, 3, "Level: %LinkLevel", RGB(255, 255, 255));
    And obviously...That's not how you do it.
    Help?
    You have to sprint the values (lets PLEASE PLEASE refrain from another big argument...)

    Code:
    char text[10];
    sprintf(text, "Level: %d", LinkLevel);
    printTextScreen(3, 3, text, RGB(255, 255, 255);
    Hope that helps

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

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

  15. #6165
    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
    You have to sprint the values (lets PLEASE PLEASE refrain from another big argument...)

    Code:
    char text[10];
    sprintf(text, "Level: %d", LinkLevel);
    printTextScreen(3, 3, text, RGB(255, 255, 255);
    Hope that helps

    -Aura
    Woked perfect. Thanks. :)

  16. #6166
    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

    Code:
    ...
    
    #include <stdarg.h>
    
    ...
    
    int screenPrintf(int x, int y, unsigned int color, char* text, ...)
    {
    	char buffer[256];
    
    	va_list ap;                             // Pointer To List Of Arguments
      	va_start(ap, text);                // Parses The String For Variables
      	vsprintf(buffer, text, ap);      // Converts Symbols To Actual Numbers
      	va_end(ap);                          // Results Are Stored In 'buffer'
    
            printTextScreen(x, y, buffer, color);
            return 0;
    }
    
    ...
    
    screenPrintf(0, 0, GU_RGBA(0, 0, 255, 255), "Hello %s!", "World");

  17. #6167
    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

    Hmm, I'm having problems with the extern thingy, when I try and compile I get
    Zitat Zitat von Cygwin
    global/global.h:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'global'
    Any ideas what I've done wrong, baring in mind I only copied what you typed (so its most likely the way I'm linking the files)?

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

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

  18. #6168
    Your Fate is Grim...
    Points: 11.640, Level: 70
    Level completed: 98%, Points required for next Level: 10
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Beiträge
    2.269
    Points
    11.640
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    if you want to use globals, just use them the normal way. (declare them outside all functions, including main.) they're underrated. as long as you dont have like 5 billion (hyperbole), you'll be fine.
    --------------------------------------------------------------------------------------

  19. #6169
    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 Grimfate126
    if you want to use globals, just use them the normal way. (declare them outside all functions, including main.) they're underrated. as long as you dont have like 5 billion (hyperbole), you'll be fine.
    Thats all fine except I'm using globals over 5-6 different files, doing this does not allow them to be declared in the normal way.

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

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

  20. #6170
    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
    Hmm, I'm having problems with the extern thingy, when I try and compile I get

    Any ideas what I've done wrong, baring in mind I only copied what you typed (so its most likely the way I'm linking the files)?

    -Aura
    did you put this in all the files?
    Code:
    #include "global.h"
    Current releases:
    Icon Action Replacer v1.5- latest release
    Current projects:
    PSP C++ IDE - Currently v1.6
    RPG Paradise - Latest version at my website

  21. #6171
    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

    Zitat Zitat von _dysfunctional
    Code:
    ...
    
    #include <stdarg.h>
    
    ...
    
    int screenPrintf(int x, int y, unsigned int color, char* text, ...)
    {
    	char buffer[256];
    
    	va_list ap;                             // Pointer To List Of Arguments
      	va_start(ap, text);                // Parses The String For Variables
      	vsprintf(buffer, text, ap);      // Converts Symbols To Actual Numbers
      	va_end(ap);                          // Results Are Stored In 'buffer'
    
            printTextScreen(x, y, buffer, color);
            return 0;
    }
    
    ...
    
    screenPrintf(0, 0, GU_RGBA(0, 0, 255, 255), "Hello %s!", "World");
    This variable length arguement list stuff is pretty cool, I knew it was possible but had never tried it. Thanks for the example.

    About all the globals, are they constants? If not its much better to keep regular variables local.
    Maybe rather than containing them all in a seperate file, you could contain them all in a structure like pspballer07 said, except then you could just pass a pointer to the globals to any function that needs them. Even that is pretty messy.

    Have a search for the 'principle of least privilege', it explians why it's a good idea to only allow code to see data that it requires but nothing else. Trying to follow it can save you alot of time finding bugs :).

  22. #6172
    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

    Heavy use of globals is considered bad programming practice due to the amount of maintenance and extra debugging needed when something goes wrong. It also breaks encapsulation and promotes heavy coupling between code modules.

    Strictly speaking, globals shouldn't be needed at all with C and C++ and you should pass the variables needed by parameter.

    http://c2.com/cgi/wiki?GlobalVariablesAreBad
    http://c2.com/cgi/wiki?GlobalVariablesConsideredHarmful

  23. #6173
    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

    Zitat Zitat von Moca
    Going by those two things I highlighted in bold, I assume you are reading 1 byte at a time. In that case, use type char. a character CAN handle 0xFF without losing any data. :\ 0xFF is the highest a char can handle.

    Why is that? If he is checking 1 byte at a time, then an unsigned char would be sufficient.

    Code:
    char y = 0xFF;
    if(y == 0xFF)
    Code:
    :290: let op: vergelijking is altijd vals omwille van het beperkte bereik van het datatype
    translation
    Code:
    warning : statement is always false because of the limit of the data type
    so why does the compiller say that then?

  24. #6174
    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
    Code:
    char y = 0xFF;
    if(y == 0xFF)
    Code:
    :290: let op: vergelijking is altijd vals omwille van het beperkte bereik van het datatype
    translation
    Code:
    warning : statement is always false because of the limit of the data type
    so why does the compiller say that then?
    it needs to be an unsigned char data type if your using values between 0 - 255

    char data types range is -128 to 127

  25. #6175
    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

    char is 0-255. It is unsigned by default.

    The problem is that the compiler sees you trying to assign an int to a char so it assumes you are giving it a value out of range of a char.

    Try:
    Code:
    // C
    char blah = (char)(0xFF);
    
    // C++
    char blah = static_cast<char>(0xFF);

  26. #6176
    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 yaustar
    char is 0-255. It is unsigned by default.

    The problem is that the compiler sees you trying to assign an int to a char so it assumes you are giving it a value out of range of a char.

    Try:
    Code:
    // C
    char blah = (char)(0xFF);
    
    // C++
    char blah = static_cast<char>(0xFF);
    i got my char info from here
    http://www.eee.bham.ac.uk/dsvp_gr/ro...e3/tsld003.htm
    Geändert von brethren (08-20-2007 um 03:14 AM Uhr)

  27. #6177
    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

    unsigned char works perfect for me , thnx=)

  28. #6178
    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

    no problem, hallo007

  29. #6179
    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

    now we are about unsigned so what exactly does it mean?

    unsigned int for example or unsigned char ... when do you use it

  30. #6180
    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

    Just checked with my debugger, looks like I was wrong and got confused with the extended ASCII table. char's range is actually -127 to 127.


 

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 .