Seite 44 von 340 ErsteErste ... 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 94 144 ... LetzteLetzte
Zeige Ergebnis 1.291 bis 1.320 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; Well heres my project, but it links to the graphics.h lib.... http://savefile.com/files/160310...

  
  1. #1291
    QJ Gamer Blue
    Points: 4.580, Level: 43
    Level completed: 15%, Points required for next Level: 170
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Beiträge
    145
    Points
    4.580
    Level
    43
    Downloads
    0
    Uploads
    0

    Standard

    Well heres my project, but it links to the graphics.h lib....
    http://savefile.com/files/160310



  2. #1292
    likes kittens....awww....
    Points: 6.975, Level: 55
    Level completed: 13%, Points required for next Level: 175
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Detroit
    Beiträge
    628
    Points
    6.975
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    Code:
    Code:
    #include "main.h"
    
    LOCAL char *readInput(FILE *fp) {
        char *retp  = NULL;
        int   curp  = 0, ch;
        int   cursz = EXP_INP_SZ_;
    
        retp = my_malloc(sizeof *retp * cursz);
    
        while ( (ch = fgetc(fp)) != EOF ) {
            if ( curp >= cursz ) {
                retp   = my_realloc(retp, sizeof *retp * (cursz + EXP_INP_SZ_));
                cursz += EXP_INP_SZ_;
            }
            retp[curp++] = ch;
        }
    
        if ( !curp ) {
            MY_FREE(retp);
            return NULL;
        }
    
        if ( retp[curp-1] == '\n' ) {
            retp = my_realloc(retp, sizeof *retp * curp);
            retp[curp-1] = 0;
        }
        else {
            retp       = my_realloc(retp, sizeof *retp * (curp + 1));
            retp[curp] = 0;
        }
        return retp;
    }
    
    LOCAL void printCipherMap(CipherText *ctptr) {
        int i, j;
        CipherChar *ccptr = ctptr->ciphermap;
        int  *ciphermap  = ctptr->plainmap;
        char *plainchars = ctptr->plainchars;
    
        for ( i = 0; i < ALPHA_SZ_; ++i ) {
            int current = ciphermap[i];
    
            if ( !ccptr[i].isPresent )
                continue;
            printf("%c => ", 'a' + i);
            if ( plainchars[i] == '?' ) {
                current = ciphermap[i];
                for ( j = 0; j < ALPHA_SZ_; ++j ) {
                    if ( current & aleph_codes[j] ) {
                        printf("%c", 'a' + j);
                        current &= ~aleph_codes[j];
                        if ( current )
                            printf(", ");
                    }
                }
            }
            else
                printf("%c", plainchars[i]);
            printf("\n");
        }
    }
    
    int main(int argc, char *argv[]) {
        char *txt;
        CipherText gctxt;
        clock_t start, end;
        double duration;
        int unsolved;
    
        if ( argc <= 1 )
            txt = readInput(stdin);
        else {
            FILE *fp = fopen(argv[1], "r");
            if ( !fp ) {
                perror("fopen failed");
                fprintf(stderr, "Input file couldn't be opened\n");
                exit(EXIT_FAILURE);
            }
            txt = readInput(fp);
        }
        if ( !txt ) {
            fprintf(stderr, "No input given!!\n");
            exit(EXIT_FAILURE);
        }
    
        start = clock();
        unsolved = solveQuip(txt, &gctxt);
        end = clock();
    
        if ( !unsolved ) {
            printf("Original Text:\n");
            printf("%s\n\n", gctxt.ociphertxt);
            printf("Deciphered Text:\n");
            printf("%s\n\n", gctxt.plaintxt);
            printf("Cipher to Plain text mapping:\n");
            printf("-----------------------------\n");
            printCipherMap(&gctxt);
            duration = (double) (end - start) / CLOCKS_PER_SEC;
            printf("Solving time: %2.1f seconds\n", duration);
        }
        else
            exit(EXIT_FAILURE);
    
        return 0;
    }
    Errors:

  3. #1293
    QJ Gamer Blue
    Points: 4.511, Level: 42
    Level completed: 81%, Points required for next Level: 39
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Germany
    Beiträge
    216
    Points
    4.511
    Level
    42
    Downloads
    0
    Uploads
    0

    Standard

    First of all, thanks for your answers!

    As for the list of artist, I think the best delimiter would be a newline-character (\n) since it will never appear in an artistname; It would look like this:

    Code:
    536			// First line, number of artists
    A perfect circle	// Name of the artist (#1)
    3			// Albumcount
    Emotive			// Name of the album (#1)
    Mer de noms		// Name of the album (#2)
    The thiteenth step	// Name of the album (#3)
    Aphex Twin		// Name of the artist (#2)
    2			// albumcount
    Come to daddy		// Name of the album (#1)
    Selected ambient works	// Name of the album (#2)
    [...]			// Name of the artist (#3)
    I thought by sending along the lenght of the artist- album-names I could allocate exactly allocate the amount of memeory I needed, not more not less. No artists- or album-name would have been cut. But as I heard allocating memory using malloc slows down the PSP, so I'll go with your suggestions.

    There is only one question left: How do I read a varialble until the next newline as quickly as possible??

  4. #1294
    Developer
    Points: 7.577, Level: 58
    Level completed: 14%, Points required for next Level: 173
    Overall activity: 0%

    Registriert seit
    Mar 2006
    Beiträge
    1.026
    Points
    7.577
    Level
    58
    Downloads
    0
    Uploads
    0

    Standard

    psp12: Learn how to code before trying to copy/paste someone elses code into your own.

    Problem fixed.

    Check out my homebrew & C tutorials at http://insomniac.0x89.org/
    Coder formerly known as Insomniac197

    tshirtz: what is irshell ??
    Atarian_: it's where people who work for the IRS go when they die

  5. #1295
    likes kittens....awww....
    Points: 6.975, Level: 55
    Level completed: 13%, Points required for next Level: 175
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Detroit
    Beiträge
    628
    Points
    6.975
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Insomniac197
    psp12: Learn how to code before trying to copy/paste someone elses code into your own.

    Problem fixed.
    ??
    im trying to port cryptoquip
    -= Double Post =-
    okay heres my problem..
    I have solveQuip declared as a function like this
    Code:
    int solveQuip(char *txt, CipherText *ctptr) {
        CipherWord **cipherwordptrs;
        int i;
        int newmap[ALPHA_SZ_];
        int ncipherwords;
        Bool nosolution = FALSE;
        char *ciphertxt = ctptr->ociphertxt;
        char plainmap[ALPHA_SZ_];
    
        processInput(txt, ctptr);
        if ( ctptr->ncipherwords <= 0 )
            return 1;
    
        cipherwordptrs = my_malloc(sizeof *cipherwordptrs * ctptr->ncipherwords);
        for ( i = 0; i < ctptr->ncipherwords; ++i ) {
            cipherwordptrs[i] = ctptr->cipherwords[i];
        }
    
        for ( i = 0; i < ctptr->ncipherwords-1; ++i ) {
            int j;
            int ikey = cipherwordptrs[i]->len;
    
            for ( j = i+1; j < ctptr->ncipherwords; ++j ) {
                int jkey = cipherwordptrs[j]->len;
                if ( ikey < jkey ) {
                    CipherWord *temp = cipherwordptrs[i];
                    cipherwordptrs[i] = cipherwordptrs[j];
                    cipherwordptrs[j] = temp;
                    ikey = jkey;
                }
            }
        }
    
        for ( i = 0; i < ctptr->ncipherwords; ++i ) {
            CipherWord *wptr = cipherwordptrs[i];
            getMatchingWordsFromDict(wptr, dicts + wptr->len - 1, ctptr->ciphermap);
        }
    
        ncipherwords = ctptr->ncipherwords;
        while ( 1 ) {
            int j;
    
            nosolution = solveWords(cipherwordptrs, ncipherwords, newmap);
            if ( !nosolution )
                break;
    
            for ( i = 0; i < ncipherwords; ++i ) {
                if ( cipherwordptrs[i]->isIgnored )
                    continue;
                cipherwordptrs[i]->isIgnored = TRUE;
                fprintf(stderr, "Couldn't find a solution, Ignoring %s and trying others\n", cipherwordptrs[i]->word);
                break;
            }
            if ( i == ncipherwords )
                break;
            for ( j = 0; j < ALPHA_SZ_; ++j ) {
                CipherChar *ccptr = ctptr->ciphermap + j;
                if ( ! ccptr->isPresent )
                    continue;
                ccptr->plainmap = ALEPH_ALL;
            }
            for ( ++i; i < ncipherwords; ++i ) {
                if ( cipherwordptrs[i]->isIgnored )
                    continue;
                cipherwordptrs[i]->curmatch = 0;
                if ( cipherwordptrs[i]->possiblewords )
                    MY_FREE(cipherwordptrs[i]->possiblewords);
                getMatchingWordsFromDict(cipherwordptrs[i], dicts + cipherwordptrs[i]->len - 1, ctptr->ciphermap);
            }
        }
    
        if ( nosolution ) {
            fprintf(stderr, "Couldn't find a solution!\n");
            return 1;
        }
        else {
            convertMapToChars(ctptr->ciphermap, newmap, plainmap);
    
            memcpy(ctptr->plainmap, newmap, sizeof *newmap * ALPHA_SZ_);
            memcpy(ctptr->plainchars, plainmap, sizeof *plainmap * ALPHA_SZ_);
    
            ctptr->plaintxt = my_malloc(sizeof *ctptr->plaintxt * strlen(ctptr->ociphertxt));
            strcpy(ctptr->plaintxt, ctptr->ociphertxt);
            ciphertxt = ctptr->plaintxt;
            for ( ; *ciphertxt; ciphertxt++ ) {
                char cipherchar = *ciphertxt;
                int  isupper;
    
                if ( !isalpha((int) cipherchar) )
                    continue;
                isupper    = isupper((int) cipherchar);
                cipherchar = tolower((int) cipherchar);
                *ciphertxt = isupper ? toupper((int)plainmap[CHAR_TO_INDEX(cipherchar)]) : plainmap[CHAR_TO_INDEX(cipherchar)];
            }
        }
        return 0;
    }
    but when i try to use it like this..
    Code:
    unsolved = solveQuip(txt, &gctxt);
    it gives me these errors
    Code:
    [email protected] /$
    $ make
    psp-gcc -I. -I/usr/psp/sdk/include -O2 -G0 -Wall   -c -o main.o main.c
    main.c : In function 'main':
    main.c(186) : error: called object 'solveQuip' is not a function
    make: *** [main.o] Error 1
    Geändert von psphacker12. (10-14-2006 um 05:27 PM Uhr) Grund: Automerged Doublepost

  6. #1296
    QJ Gamer Blue
    Points: 4.580, Level: 43
    Level completed: 15%, Points required for next Level: 170
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Beiträge
    145
    Points
    4.580
    Level
    43
    Downloads
    0
    Uploads
    0

    Standard

    Again, heres my project:
    http://savefile.com/files/160310
    Please someone help, whats wrong with it? The graphics.h connects to it fine..I dont know whats wrong.

  7. #1297
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Lukeson
    But as I heard allocating memory using malloc slows down the PSP, so I'll go with your suggestions.
    That's plain utter bull. malloc shouldn't be used inside inner loops of realtime-apps, yes, but even there it is possible to some extent. Whoever told you that, don't listen to him.

    There is only one question left: How do I read a varialble until the next newline as quickly as possible??
    Uh... read char by char into a buffer until one char turns up as newline. Stop. Repeat. Pretty simple :P
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

  8. #1298
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    ugh...

    1. Remove the ] bracket at the start of your main.c...
    2. You dont need that extern C stuff since you're already saying it's in C by having main file main.c...

    That should fix it.

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  9. #1299
    QJ Gamer Blue
    Points: 4.580, Level: 43
    Level completed: 15%, Points required for next Level: 170
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Beiträge
    145
    Points
    4.580
    Level
    43
    Downloads
    0
    Uploads
    0

    Standard

    All right its actually working now :P
    But is there a way to make it so when I press Up or Down he doesnt move like 1 inch?? Like when i press it he doesnt keep moving he just stops.
    How do i make it so when i hold it down he keeps moving, and when i release he stops?

  10. #1300
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Gonrai - You specifically said to make him only move once (in the code). Remove the UP and DOWN if statements (the button input) OUT of the if statement that says if oldpad ~=pad or w/e.

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  11. #1301
    Developer
    Points: 10.075, Level: 67
    Level completed: 7%, Points required for next Level: 375
    Overall activity: 0%

    Registriert seit
    Sep 2005
    Ort
    Sweden
    Beiträge
    941
    Points
    10.075
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Insomniac197
    You need to add something like this mate, at the end of the makefile:

    Code:
    noelf: kxploit
    	rm -f myfile.elf
    Then when you come to compile just put 'make noelf'.

    Note that the rm line is indented with a tab, this is required. You can add more lines after that if you wish to delete other files etc, these need a tab indent also.
    Thanks for the code, I appreciate it. The code you gave me worked like a charm. But if only want a "regular" eboot I'll first have to type "make" then "make noex" (I have deleted the kxploit line). Is there a way to short it down so I'll only have to type one line in cygwin?

    Psp12.: Try changing 'int' to 'void', that works sometimes with errors like these. At least I had an error that said that it was not a function and it took me a day to figure out what was worng. But I still don't know why it didn't work when I was using int :)
    Geändert von SodR (10-15-2006 um 01:36 AM Uhr)

  12. #1302
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    SodR - Im not sure what your question really is, but to spit out a NON kxploit eboot, just type 'make' rather than 'make kxploit'. Once again, Im not 100% what you and Insomniac had discussed and am a little too lazy to read back :o

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  13. #1303
    Developer
    Points: 10.075, Level: 67
    Level completed: 7%, Points required for next Level: 375
    Overall activity: 0%

    Registriert seit
    Sep 2005
    Ort
    Sweden
    Beiträge
    941
    Points
    10.075
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von SG57
    SodR - Im not sure what your question really is, but to spit out a NON kxploit eboot, just type 'make' rather than 'make kxploit'. Once again, Im not 100% what you and Insomniac had discussed and am a little too lazy to read back :o
    Lol, no that is not what I'm asking :) I just wondered if you could type make clean without first having to type make to generate the eboot. That is so I wont have to type two lines into cygwin ;)
    Geändert von SodR (10-15-2006 um 02:35 AM Uhr)

  14. #1304
    QJ Gamer Blue
    Points: 4.511, Level: 42
    Level completed: 81%, Points required for next Level: 39
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Germany
    Beiträge
    216
    Points
    4.511
    Level
    42
    Downloads
    0
    Uploads
    0

    Standard

    Uh... read char by char into a buffer until one char turns up as newline. Stop. Repeat. Pretty simple :P
    Sounds pretty slow...
    Wouldn't it even be faster to write the string to a file and use fgets? That's pretty 'dirty' and I guess fgets does nothing else than doing the char-by-char-thing, but maybe not?

  15. #1305
    AKA Homer
    Points: 12.596, Level: 73
    Level completed: 37%, Points required for next Level: 254
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Sweden
    Beiträge
    1.779
    Points
    12.596
    Level
    73
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Lukeson
    Sounds pretty slow...
    Wouldn't it even be faster to write the string to a file and use fgets? That's pretty 'dirty' and I guess fgets does nothing else than doing the char-by-char-thing, but maybe not?
    That would probably be the slowest way to do it. Just do something like
    Code:
    for(int i=0;i<strlen(str);i++)
    {
      if(str[i]=='\n') //newline
    }
    It should be pretty fast.


    Click Here if you want a Winamp Currently Playing Userbar like the one above.

  16. #1306
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Lukeson
    Sounds pretty slow...
    Wouldn't it even be faster to write the string to a file and use fgets? That's pretty 'dirty' and I guess fgets does nothing else than doing the char-by-char-thing, but maybe not?
    Writing to a file just to read again byte for byte? How should that ever be faster? And yes, fgets also only reads byte for byte, but from a file instead of from memory which is hundreds times slower, plus the additional writing which is even more slower.
    for(int i=0;i<strlen(str);i++)
    {
    if(str[i]=='\n') //newline
    }
    That's somewhat how I imagined and it's the fastest way possible by any means. Do it like that.
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

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

    how do you do this:

    let the program while in a loop return to the beginning of that loop
    for exemple
    Code:
        for(leerlingen=1; leerlingen<=21;) {
        
        cout<<"geef de score van leerling "<<leerlingen;
        cin>>punten[leerlingen];
        cout<<"\n";
        leerlingen +1;
       /************************************************
      *********************return now to the beginning*******/
        if (leerlingen=21) {
                          break;
                          }
                          }
    }
    you see , so it stay asking it ,untiln the variabel "leerlingen = 21" ofcoures;)

  18. #1308
    Developer
    Points: 10.075, Level: 67
    Level completed: 7%, Points required for next Level: 375
    Overall activity: 0%

    Registriert seit
    Sep 2005
    Ort
    Sweden
    Beiträge
    941
    Points
    10.075
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von hallo007
    how do you do this:

    let the program while in a loop return to the beginning of that loop
    for exemple

    you see , so it stay asking it ,untiln the variabel "leerlingen = 21" ofcoures;)
    I don't really understand what you mean but here is an example of a while loop;

    Code:
    int x = 0;
    
    // Endless loop if we don't break it using 'break;'
    while(1) {
    
    x++;
    
    // If the integer x = 21 we'll break the loop
    if(x==21) {
    break;
    }
    
    }
    
    // This code will only run when we have broke out of the loop
    I hope it'll help

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

    no i dont help , lol
    i understand what a loop is
    but i wanne repeat the loop
    so if the user put a value for number 1 , it ask a value for number 2 , i have that , the only thing i need to do is that it's start again from the beginning
    for exempla
    Code:
    what's the value of number 1? 4
    /*now it repeats and x is one more so it prints number 2 and save the value to arrey 2*/
    what's the value of number 2? 7
    understand?? srry , i know my english is bad

  20. #1310
    AKA Homer
    Points: 12.596, Level: 73
    Level completed: 37%, Points required for next Level: 254
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Sweden
    Beiträge
    1.779
    Points
    12.596
    Level
    73
    Downloads
    0
    Uploads
    0

    Standard

    Why don't you do it like this
    Code:
    int a = 0;
    while(1)
    {
      cin>>var;
      a++;
      if(a==21)
        break;
      /*else
      {
        //Not needed at all, just showing you the continue statement
        continue;
      }*/
    }
    Or in your case
    Code:
    //Reset to avoid any memory problems
    leerlingen = 0;
    while(1)
    {
      cout<<"geef de score van leerling "<<leerlingen;
      cin>>punten[leerlingen];
      cout<<"\n";
      leerlingen++;
      if (leerlingen==21) 
         break;
    }


    Click Here if you want a Winamp Currently Playing Userbar like the one above.

  21. #1311
    QJ Gamer Platinum
    Points: 57.528, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Dec 2005
    Ort
    h0000000rj
    Beiträge
    12.867
    Points
    57.528
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard

    You could also put the loop inside another loop. Then, in the inside loop, make it check which run through the outside loop it is. Example:
    Code:
    for(x=0;x<5;x++)
    {
       for(y=0;y<5;y++)
       {
          switch(x)
          {
          case 0:
             // something to do the first time through
             break;
          case 1:
             // something to do the second time through
             break;
          case 2:
             // something to do the third time through
             break;
          case 3:
             // something to do the fourth time through
             break;
          case 4:
             // something to do the fifth time through
             break;
          }
       }
    }
    Or...
    Code:
    for(x=0;x<5;x++)
    {
       printf("What's the value of number %i?\n", x);
       //get input here... however you want to do it
    }
    [I fail @ life]

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

    Code:
        for(leerlingen=1; leerlingen<=21;) {
        
        cout<<"geef de score van leerling "<<leerlingen;
        cin>>punten[leerlingen];
        cout<<"\n";
        leerlingen +1; // This line doesn't do anything to 'leerlingen'
       /************************************************
      *********************return now to the beginning*******/
        if (leerlingen=21) {
                          break;
                          }
                          }
    }
    Should be:
    Code:
    for( leerlingen = 0; leerlingen < 21; ++leerlingen ) {
        
        cout << "geef de score van leerling " << leerlingen;
        cin >> punten[leerlingen];
        cout << endl;
    }

  23. #1313
    QJ Gamer Platinum
    Points: 57.528, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Dec 2005
    Ort
    h0000000rj
    Beiträge
    12.867
    Points
    57.528
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard

    Heh. Looks like we all missed that he wasn't incrementing the value, except for you. Also:
    Code:
    for( leerlingen = 0; leerlingen < 21; ++leerlingen ) {
        
        cout << "geef de score van leerling " << leerlingen;
        cin >> punten[leerlingen];
        cout << endl;
    }
    will start storing values in the second array element.
    Code:
    for( leerlingen = 0; leerlingen < 21; ++leerlingen ) {
        
        cout << "geef de score van leerling " << leerlingen;
        cin >> punten[leerlingen-1];
        cout << endl;
    }
    will start from the first :)
    [I fail @ life]

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

    so when i put in the first value , the program do first the second loop (and repeats it 100times ) and then it crashes

  25. #1315
    Developer
    Points: 10.075, Level: 67
    Level completed: 7%, Points required for next Level: 375
    Overall activity: 0%

    Registriert seit
    Sep 2005
    Ort
    Sweden
    Beiträge
    941
    Points
    10.075
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Now I got a question for you guys:

    I use this posted by Insomniac :) at psp-programming to generate a random number:

    Code:
    int getRandomNum(int lo, int hi)
    {
    SceKernelUtilsMt19937Context ctx;
    u32 rand_val = sceKernelUtilsMt19937UInt(&ctx);
    rand_val = lo + rand_val % hi;
    return (int)rand_val;
    }
    Then I got an array that looks like this:
    Code:
    char color[5];
    // Yellow
    color[1] = 0;
    // Green
    color[2] = 29;
    // Black
    color[3] = 58;
    // Red
    color[4] = 87;
    // Blue
    color[5] = 116;
    The numbers are offsets if anyone wonders.

    Then I generate a random number between 1 and 5 like this:
    Code:
    	int RandomNum;
    	RandomNum = getRandomNum(1,5);
    Then I finaly want to use the random number and blit the image:
    Code:
    blitAlphaImageToScreen(color[RandomNum],0,29,25, hex_image, 132, 222);
    blitAlphaImageToScreen(color[RandomNum],0,29,25, hex_image, 132, 247);
    This compiles fine but when I try it on the psp it'll always generate the number 1 = the color/offset is always 0/yellow. I know I can do this fix it "the lazy way" using alot of if statements but I got [f]Alot[/f] of different images I'm bliting and it would take forever to write if statements to them all.

    Any thoughts?

  26. #1316
    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 FreePlay
    Code:
    for( leerlingen = 0; leerlingen < 21; ++leerlingen ) {
        
        cout << "geef de score van leerling " << leerlingen;
        cin >> punten[leerlingen-1];
        cout << endl;
    }
    will start from the first :)
    Woah. That would start from -1 not 0. On the first loop, leerlingen = 0, it doesnt increment until the end of the first loop.

  27. #1317
    Developer
    Points: 5.359, Level: 47
    Level completed: 5%, Points required for next Level: 191
    Overall activity: 0%

    Registriert seit
    Feb 2006
    Ort
    Norway
    Beiträge
    384
    Points
    5.359
    Level
    47
    Downloads
    0
    Uploads
    0

    Standard

    You need to seed the randomizer.

    Not sure how you do it with that way.

    but you could do:

    srand(time(NULL));
    RandomNum = rand() % (5+1);


  28. #1318
    Developer
    Points: 10.075, Level: 67
    Level completed: 7%, Points required for next Level: 375
    Overall activity: 0%

    Registriert seit
    Sep 2005
    Ort
    Sweden
    Beiträge
    941
    Points
    10.075
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von waterbottle
    You need to seed the randomizer.

    Not sure how you do it with that way.

    but you could do:

    srand(time(NULL));
    RandomNum = rand() % (5+1);
    Thanks It worked fine. I guess there is no "magic" way of making the integer change every time you use it? I.e.
    Code:
    // First a number is generated here:
    blitAlphaImageToScreen(color[RandomNum],0,29,25, hex_image, 132, 222);
    // A new number is automaticly generated using the same integer
    blitAlphaImageToScreen(color[RandomNum],0,29,25, hex_image, 132, 247);
    That would save me alot of time/space in the source.

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

    thnx , i m nearly there now i want to parts the punten[leerlingen]


    but how do you adds them up if you dont know how many there gonna be????????

  30. #1320
    Developer
    Points: 7.577, Level: 58
    Level completed: 14%, Points required for next Level: 173
    Overall activity: 0%

    Registriert seit
    Mar 2006
    Beiträge
    1.026
    Points
    7.577
    Level
    58
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von SodR
    Thanks It worked fine. I guess there is no "magic" way of making the integer change every time you use it?
    If you read the full post mate it shows how to seed the Mersenne Twister etc.

    http://www.psp-programming.com/dev-f...pic.php?t=1076

    I found it a lot more random than using the rand() stuff.
    -= Double Post =-
    Code:
    // First a number is generated here:
    blitAlphaImageToScreen(color[RandomNum],0,29,25, hex_image, 132, 222);
    // A new number is automaticly generated using the same integer
    blitAlphaImageToScreen(color[RandomNum],0,29,25, hex_image, 132, 247);
    I think you could do something like this...:

    Code:
    blitAlphaImageToScreen(color[GetRandomNum(0, 10)],0,29,25, hex_image, 132, 222);
    Geändert von Insomniac197 (10-15-2006 um 09:08 AM Uhr) Grund: Automerged Doublepost

    Check out my homebrew & C tutorials at http://insomniac.0x89.org/
    Coder formerly known as Insomniac197

    tshirtz: what is irshell ??
    Atarian_: it's where people who work for the IRS go when they die


 

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 .