Seite 204 von 340 ErsteErste ... 104 154 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 254 304 ... LetzteLetzte
Zeige Ergebnis 6.091 bis 6.120 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 Archaemic So many things wrong with both of those, I don't know where to begin @@ don't nitpick ...

  
  1. #6091
    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 Archaemic
    So many things wrong with both of those, I don't know where to begin @@
    don't nitpick i'm trying to get a simple point across not an entire encyclopedia of coding standards.



  2. #6092
    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

    There's a difference between trying to write code that's clean and code that will compile. That won't even compile. Or if it will, it'll give you a mess of warnings and crash instantly when run.
    pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ

  3. #6093
    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 califrag
    I don't see how using "sprintf" and buffers can simplify my code:

    My version:
    Code:
    char myCharVariable1 = "Sometext", myCharVariable2 = "MoreText"; int myIntVariable = 2;
    printf("%s %02d %s", myCharVariable1, myIntVariable, myCharVariable2);
    Your version:
    Code:
    char myCharVariable1, myCharVariable2; int myIntVariable;
    sprintf(myCharVariable1, "Sometext");
    sprintf(myCharVariable2, "Moretext");
    myIntVariable = 2;
    sprintf(buffer, "%s %02d %s", myCharVariable1, myIntVariable, myCharVariable2);
    printf("%s", buffer);
    hmm.. keep using all the sprintf's and buffers you need and i will keep my minimalist approach. Thanks! Plus it all depends on what you are doing and whether your text is static or not, and if it is not static of course you will need to use a sprintf to get your variable initialized with the data you need.
    Not nitpicking but i'll just say a couple of things i have noticed from the above posts:

    1) As you noted, whether you use a buffer or not depends on if you plan on changing the contents of the string.

    - If the string is constant over the entire duration of the program
    just use a constant pointer to a string literal.

    - If the string changes use a character array and modify the string
    with strcpy/sprintf ect.

    You could even just have constant string literals and a character pointer that changes which string it points to, it's up to personal preference, there is no wrong or right way.
    Keeping things as straight foward as possible like you have is a good idea however :).

    2) The string constants in both examples have type 'char', this is incorrect, they should either be a char pointer ('char*' or 'char variable_name[]') or a char array of the appropriate size (char variable_name[size]).

    3) You cannot use sprintf to output into a string literal. sprintf is only used to write into a character array defined by the programmer. This is a common mistake, it is important to note that a pointer and an array are not the same thing, the name of an array is a constant pointer but the actual body is a memory space. Before sprintf'ing to a pointer make sure that it points to an array of memory big enough to hold the data.

    Hope this helps :)
    Geändert von psp_jono (08-16-2007 um 06:06 PM Uhr)

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

    wow 150 pages into this thread i decide to open my mouth and try to offer some help about a stupid printf function that gerbils can understand. i'm not trying to write code for someone to copy paste into their program and compile immediately.. if i was i'd post the source to hello world. i was simply trying to demonstrate the many different ways that printf can be used WITHOUT sprintf or strcpy or buffers of any kind. the guy I was ORIGINALLY talking to wanted to put static text into his program.. anyways i've learned a lot from this thread.. don't offer any help unless you're just going to copy paste some source code for someone else to copy paste into their program. thanks.

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

    ??? Sorry to offend, just trying to help mate :)

  6. #6096
    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 psp_jono
    ??? Sorry to offend, just trying to help mate :)
    no not you jono you actually kinda backed me up a little thanks, if you notice i made my code more "compileable" for those who are so nitpicky... :)

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

    ok. im looking for function which would make from string:

    hello all

    just:

    all

    basicly, i need to cut away 1st 6 letters? i just cant remeber that function name..... string something

  8. #6098
    Banned for LIFE
    Points: 18.744, Level: 86
    Level completed: 79%, Points required for next Level: 106
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    East London, England
    Beiträge
    2
    Points
    18.744
    Level
    86
    Downloads
    0
    Uploads
    0

    Standard

    I need to know how i would go about doing some animation. Any links ?

  9. #6099
    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 myschoo
    ok. im looking for function which would make from string:

    hello all

    just:

    all

    basicly, i need to cut away 1st 6 letters? i just cant remeber that function name..... string something
    The function you can use is strcpy in the header <string.h>.

    Use it like this -
    Code:
    char hello[] = "hello all";
    strcpy(hello,hello+6);
    What that does is copies the data in the string starting at 6 bytes in front of the address of the array until the null byte is reached. It copies it to the beginning of the string.

    You would use the function like this - strcpy(destination,source );

    I'll explain a bit more about arrays and whatnot if needed later. for now, I need sleep.
    [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. #6100
    Banned for LIFE
    Points: 18.744, Level: 86
    Level completed: 79%, Points required for next Level: 106
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    East London, England
    Beiträge
    2
    Points
    18.744
    Level
    86
    Downloads
    0
    Uploads
    0

    Standard

    Ive been googling but still cannot find anything. Is there any source code i can obtain that will show me the basics and i can then build upon ?

  11. #6101
    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

    animation? u can use spritesheet and change coordinates using timer or something similar

    Moca: sweet thats what i was looking for. thx

  12. #6102
    Banned for LIFE
    Points: 18.744, Level: 86
    Level completed: 79%, Points required for next Level: 106
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    East London, England
    Beiträge
    2
    Points
    18.744
    Level
    86
    Downloads
    0
    Uploads
    0

    Standard

    A timer is the only way ?

  13. #6103
    Avada Kedavra
    Points: 6.813, Level: 54
    Level completed: 32%, Points required for next Level: 137
    Overall activity: 0%

    Registriert seit
    May 2007
    Ort
    Spain
    Beiträge
    703
    Points
    6.813
    Level
    54
    Downloads
    0
    Uploads
    0

    Standard

    With OSLib its pretty easy to make animations:)

  14. #6104
    Banned for LIFE
    Points: 18.744, Level: 86
    Level completed: 79%, Points required for next Level: 106
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    East London, England
    Beiträge
    2
    Points
    18.744
    Level
    86
    Downloads
    0
    Uploads
    0

    Standard

    Is OSLib completed for psp ?

    btw thanks for the recommendation im reading up now.

  15. #6105
    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 myschoo
    animation? u can use spritesheet and change coordinates using timer or something similar

    Moca: sweet thats what i was looking for. thx
    Code:
    char helloStr[10] = "Hello all";
    printf(helloStr); // Hello all
    helloStr += 6;
    printf(helloStr); // all
    Would also do the trick.

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

    Zitat Zitat von eldiablov
    Is OSLib completed for psp ?

    btw thanks for the recommendation im reading up now.
    oslib is the most completed library in existance for the psp :)
    --------------------------------------------------------------------------------------

  17. #6107
    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 _dysfunctional
    Code:
    char helloStr[10] = "Hello all";
    printf(helloStr); // Hello all
    helloStr += 6;
    printf(helloStr); // all
    Would also do the trick.
    I'm gonna throw in another one just for fun.
    Code:
    char *textall;
    char texthelloall[] = "Hello All";
    textall = strstr(texthelloall,"All");
    I am pretty sure that would work
    Current releases:
    Icon Action Replacer v1.5- latest release
    Current projects:
    PSP C++ IDE - Currently v1.6
    RPG Paradise - Latest version at my website

  18. #6108
    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

    whats the diffrence between:

    char *textall; and char textall;

  19. #6109
    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

    One is a pointer and the other one isn't...
    pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ

  20. #6110
    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

    Zitat Zitat von myschoo
    whats the diffrence between:

    char *textall; and char textall;
    the first one creates a pointer to a char. the name of the POINTER is textall.

    the second on creates a char. the name of the CHAR is textall.
    --------------------------------------------------------------------------------------

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

    thx. i think i understand :)

  22. #6112
    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 myschoo
    thx. i think i understand :)
    How would one change the text under the title?

  23. #6113
    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 _dysfunctional
    Code:
    char helloStr[10] = "Hello all";
    printf(helloStr); // Hello all
    helloStr += 6;
    printf(helloStr); // all
    Would also do the trick.
    Wait...you can't do that O_o

    I kinda see what you are tryin' to do but... You can't modify the address of an array o_O. Unless if I missed something huge.
    [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]

  24. #6114
    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

    Zitat Zitat von Mr305
    How would one change the text under the title?
    not possible anymore.
    before, premium member could pay it for non-prem.

  25. #6115
    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
    Wait...you can't do that O_o

    I kinda see what you are tryin' to do but... You can't modify the address of an array o_O. Unless if I missed something huge.
    Your right, your right.
    It would work as a pointer, but not as a plain array. My mistake.

  26. #6116
    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

    Code:
    char helloStr[10] = "Hello all";
    printf(helloStr); // Hello all
    helloStr += 6;
    printf(helloStr); // all
    Would have worked with the use of another pointer,

    Code:
    char helloStr[10] = "Hello all";
    printf(helloStr); // Hello all
    char* allStr = helloStr;
    allStr += 6;
    printf(allStr); // all
    or without pointer arithmetic,

    Code:
    char helloStr[10] = "Hello all";
    printf(helloStr); // Hello all
    char* allStr = &helloStr[6];
    printf(allStr); // all
    or without storing a pointer at all,

    Code:
    char helloStr[10] = "Hello all";
    printf(helloStr); // Hello all
    printf(&helloStr[6]); // all
    Geändert von psp_jono (08-16-2007 um 05:44 PM Uhr)

  27. #6117
    QJ Gamer Blue
    Points: 3.680, Level: 38
    Level completed: 20%, Points required for next Level: 120
    Overall activity: 0%

    Registriert seit
    Apr 2007
    Beiträge
    172
    Points
    3.680
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    jono wouldn't the last example only display the 6th character not up to the 6th character?

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

    I'm fairly certain jono is right on all points in that post.
    pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ

  29. #6119
    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 seenit
    jono wouldn't the last example only display the 6th character not up to the 6th character?
    It would print the 6th character and every character following until a null ('\0') character is encountered :).

    Heres another one:

    Code:
    char helloStr[10] = "Hello all";
    printf( helloStr);                         // prints "Hello all"
    printf( helloStr + 6);                   // prints "all"
    I'm not a big fan of pointer arithmetic most of the time, it can make code a fair bit harder to understand. Although at times it does make sense to use it.

    EDIT: null character was '\n' rather than '\0'. oops :o.

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

    Ehh, not quite right on all points this time, jono. \n is the newline character. \0 is the null character.
    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 .