Seite 169 von 340 ErsteErste ... 69 119 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 219 269 ... LetzteLetzte
Zeige Ergebnis 5.041 bis 5.070 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 -PSPJunkie- You need to make you image variable global. So define the image in a ".h" file and ...

  
  1. #5041
    QJ Gamer Silver
    Points: 7.278, Level: 56
    Level completed: 64%, Points required for next Level: 72
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    Pimp'en in the US F#
    Beiträge
    1.254
    Points
    7.278
    Level
    56
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von -PSPJunkie-
    You need to make you image variable global. So define the image in a ".h" file and you will be able to manipulate it from any file that you include it from.
    Does that mean i would put,

    Code:
    extern Image* zombiepic;
    in Game.h?

    I also have
    Code:
     
    zombie[0].x;
    zombie[0].y;
    that is defined in enemyAI.c which i would like it to be "seen" by game.c.
    would i put the two in enemyAI.h as
    Code:
     
    extern int zombie[0].x;
    extern int zombie[0].y;
    ?


    The Wentire Worls in two Sectors....
    When did I get dev statz?
    Spoiler for my PSP homebrewReleases:
    Ace of Space V1|PvP Pong Online|PvP Pong v3 | 3.03 BlackShark Custom Firmware
    (PvP Pong DL'ed well over 2403 times combined! get yours now!)
    Spoiler for Great Quotes:

    "No Snowflake in an Avalanche ever feels responsible....." - Fortune Cookie.

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

    okay here is what you do.

    game.h:
    Code:
    extern Image *zombiepic;
    extern int zombie[0].x;
    extern int zombie[0].y;
    game.c:
    Code:
    Image *zombiepic;
    enemyAI.c:
    Code:
    int zombie[0].x;
    int zombie[0].y;
    and have all the .c files #include "game.h" and have all the files in the makefile. What "extern" does is it says that Image *zombiepic was defined but in a different location which is in game.c
    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. #5043
    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 BlackShark
    Does that mean i would put,

    Code:
    extern Image* zombiepic;
    in Game.h?

    I also have
    Code:
     
    zombie[0].x;
    zombie[0].y;
    that is defined in enemyAI.c which i would like it to be "seen" by game.c.
    would i put the two in enemyAI.h as
    Code:
     
    extern int zombie[0].x;
    extern int zombie[0].y;
    ?
    the first part is right, but the zombie part is not. instead of doing this:

    Code:
     
    extern int zombie[0].x;
    extern int zombie[0].y;
    you should make the whole zombie external:

    Code:
     
    extern Zombie zombie[NUM_ZOMBIES];
    something like that.

    and pspballer, why are are defining the image twice in two files? you post make no sense. could you re-explain please?
    --------------------------------------------------------------------------------------

  4. #5044
    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 Altimax
    Why do all the entries on this list print on the same line? It's almost as if it's ignoring the "\n".
    Code:
    void readDir(char* directory) {
            int z;
    	SceUID dir = sceIoDopen(directory);
            if(dir > 0)
            {
            	SceIoDirent folder;
    	        memset(&folder, 0, sizeof(SceIoDirent)); 
    	        while(sceIoDread(dir, &folder) > 0){//if there is still something in folder
    		      printf("%s\n",folder.d_name);
                          z+=8;//text height
                          if(z > 272) break;//screen height
    	              }
    	        sceIoDclose(dir);
                    }
    }
    
    int main() {
    	pspDebugScreenInit();
    	SetupCallbacks();
    	readDir("ms0:/PSP/GAME/");
    	sceKernelSleepThread();
    	return 0;
    }

  5. #5045
    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 Grimfate126
    pspballer, why are are defining the image twice in two files? you post make no sense. could you re-explain please?
    When you use 'extern', it only means that the var exists somewhere, so you have to declare the "real" var in a C file. There is an article about this somewhere but my internet can't stay connected
    Current releases:
    Icon Action Replacer v1.5- latest release
    Current projects:
    PSP C++ IDE - Currently v1.6
    RPG Paradise - Latest version at my website

  6. #5046
    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

    ah yes, you're right. just checked my book

    havent used extern in a while ;)
    --------------------------------------------------------------------------------------

  7. #5047
    QJ Gamer Silver
    Points: 7.278, Level: 56
    Level completed: 64%, Points required for next Level: 72
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    Pimp'en in the US F#
    Beiträge
    1.254
    Points
    7.278
    Level
    56
    Downloads
    0
    Uploads
    0

    Standard

    ok, the only problem i get now is,

    Code:
    enemyAI.h(5) syntax error before 'zombie' 
    enemyAI.h(5) [Warning] type defaults to 'int' in declaration of 'zombie' 
    enemyAI.h(5) [Warning] data definition has no type or storage class

    here is enemyAI.h,

    Code:
    #ifndef __ENEMYAI__
    #define __ENEMYAI__
    
    extern void enemyAI();
    extern ENEMY zombie[1];
    #endif
    EDIT: also, How would I Load an Eboot? IE, load the one I am using to "restart" it?
    Geändert von BlackShark (06-15-2007 um 01:35 AM Uhr)
    The Wentire Worls in two Sectors....
    When did I get dev statz?
    Spoiler for my PSP homebrewReleases:
    Ace of Space V1|PvP Pong Online|PvP Pong v3 | 3.03 BlackShark Custom Firmware
    (PvP Pong DL'ed well over 2403 times combined! get yours now!)
    Spoiler for Great Quotes:

    "No Snowflake in an Avalanche ever feels responsible....." - Fortune Cookie.

  8. #5048
    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 BlackShark
    ok, the only problem i get now is,

    Code:
    enemyAI.h(5) syntax error before 'zombie' 
    enemyAI.h(5) [Warning] type defaults to 'int' in declaration of 'zombie' 
    enemyAI.h(5) [Warning] data definition has no type or storage class

    here is enemyAI.h,

    Code:
    #ifndef __ENEMYAI__
    #define __ENEMYAI__
    
    extern void enemyAI();
    extern ENEMY zombie[1];
    #endif
    Re-read the error and look specifically at what it is referring to. Think of reasons of why it can't figure out what to do. One of the skills that any programmer must learn is to be able to compiler and execute code in their head. This includes the highlighting of errors.
    Spoiler for answer:

    In the file scope of enemyAI.h, you haven't defined what the ENEMY structure is. You will have to #include the file that has the class declaration of enemy in this file

  9. #5049
    QJ Gamer Silver
    Points: 7.278, Level: 56
    Level completed: 64%, Points required for next Level: 72
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    Pimp'en in the US F#
    Beiträge
    1.254
    Points
    7.278
    Level
    56
    Downloads
    0
    Uploads
    0

    Standard

    But enemyAI.c is what defines it, how would i include that in the enemyAI.h file?

    #include "enemyAI.c" ?
    The Wentire Worls in two Sectors....
    When did I get dev statz?
    Spoiler for my PSP homebrewReleases:
    Ace of Space V1|PvP Pong Online|PvP Pong v3 | 3.03 BlackShark Custom Firmware
    (PvP Pong DL'ed well over 2403 times combined! get yours now!)
    Spoiler for Great Quotes:

    "No Snowflake in an Avalanche ever feels responsible....." - Fortune Cookie.

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

    No, don't EVER include source files. Just move the definition of ENEMY from the source file to the header file.

  11. #5051
    QJ Gamer Silver
    Points: 7.278, Level: 56
    Level completed: 64%, Points required for next Level: 72
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    Pimp'en in the US F#
    Beiträge
    1.254
    Points
    7.278
    Level
    56
    Downloads
    0
    Uploads
    0

    Standard

    I knew that wouldn't work :P, Thanks!

    alright, i know i must be driving you all crazy with this question attack of mine, so weather this is the last one I have or not, this will be the very last one i post....for tonight, (this morning, what ever :P)

    ok, im still getting errors for that damn Image zombiepic :/,
    the error list is this,

    Code:
      [Linker error] undefined reference to `zombiepic' 
     K:\Black Pack\WorldWarZ\enemyAI.o R_MIPS_GPREL16 against `zombiepic'
    now if you remember, zombiepic is an Image I load in Game.c and would also like it to be available in enemyAI.c.

    I checked enemyAI.c to make sure it had Game.h included, here is the game.h

    Code:
    #ifndef __GAME__
    #define __GAME__
    
    extern void Game();
    extern Image *zombiepic;
        
    #endif
    I tried "extern Image* zombiepic;" too
    I also tried putting the * on zombiepic in the Game.c while loading like

    Code:
    Image *zombiepic = loadImage("zombie");

    but that didn't work either, I made sure that enemyAI.h was included in the Game.c too. Any ideas?
    The Wentire Worls in two Sectors....
    When did I get dev statz?
    Spoiler for my PSP homebrewReleases:
    Ace of Space V1|PvP Pong Online|PvP Pong v3 | 3.03 BlackShark Custom Firmware
    (PvP Pong DL'ed well over 2403 times combined! get yours now!)
    Spoiler for Great Quotes:

    "No Snowflake in an Avalanche ever feels responsible....." - Fortune Cookie.

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

    Post up full code of Game.c as it is at the moment with that error.
    -= Double Post =-
    Code:
    // Header file
    #ifndef (BLAH_H)
    #define (BLAH_H)
    
    extern int * gAGlobal;
    
    #endif // (BLAH_H)
    Code:
    // Source file where gAGlobal is instantiated 
    // No need to include header file
    // IN GLOBAL SCOPE!
    int * gAGlobal = NULL;
    
    void blah( void )
    {
    	gAGlobal = someRandomValue;
    }
    Geändert von yaustar (06-15-2007 um 05:11 AM Uhr) Grund: Automerged Doublepost

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

    Spoiler for code:
    Code:
    /INCLUDES
    #include <stdlib.h>
    #include <malloc.h>
    #include <pspdisplay.h>
    #include <psputils.h>
    #include <png.h>
    #include <pspgu.h>
    #include <string>
    #include <pspkernel.h>
    #include <pspctrl.h>
    
    #include "desktop.h"
    #include "graphics/graphics.h"
    #include "graphics/images.h"
    #include "io/iO.h"
    #include "variabels.h"
    
    //DEFINES
    #define blitImage  blitAlphaImageToScreen        //Blit image to screen (GUI)
    #define printg     printTextScreen               //GUI text printfs
    #define printf     pspDebugScreenPrintf          //Debug console
    
    //MODULE INFO
    PSP_MODULE_INFO("Desktop Example" , 0x1000, 1, 1);
    PSP_MAIN_THREAD_ATTR(0);
    
    Image *desktopBack;
    
    class fileInfo
    {
          private:                         
                  long int size;           //the size in bytes
                  long int kbSize;         //the size in kilobytes
                  long int mbSize;         //the size in megabytes
                  std::string folder;      //the folder path
                  std::string extension;   //the file extension   
                  std::string fileName;    //name without extension                                                                                                                              
          public:
                  int file;                //file or folder , file = 1 , folder = 0;                 
                  void researchDir(std::string directory);
                  int xFile;               //coordinates on desktop
                  int yFile;               // same here  
                  int xEndFile;            //the coordinates of the last pixel
                  int yEndFile;            //same here
                  std::string name;        //file name (with extension)
                  std::string path;        //the compolete file path   
    };
    fileInfo fileBuffer[222];
    
    int LoadStartModule(char *path)
    {
        u32 loadResult;
        u32 startResult;
        int status;
    
        loadResult = sceKernelLoadModule(path, 0, NULL);
        if (loadResult & 0x80000000) return -1;
        
        startResult =   sceKernelStartModule(loadResult, 0, NULL, &status, NULL);
    
        if (loadResult != startResult) return -2;
    
        return 0; 
    }
    int isFile( std::string filename)
    { 
    	SceIoStat stats;
    	sceIoGetstat( filename.c_str(), &stats);//get the stats
    	
    	if ( stats.st_mode & FIO_S_IFDIR) //directory?
    	{
             return 0; //if directory 
             }
    	else 
    	{
    		return 1;  //if file
        }
    }
    void fileInfo::researchDir(std::string directory)
    {
         int x = 10;
         int y = 10;
         getFileList(directory); 
         for(unsigned int loop = 0; loop < z; loop++ )
         {
               fileBuffer[loop].path.clear();        
               fileBuffer[loop].path.append( directory, 0 , directory.size());   
               fileBuffer[loop].path.append( fileList[loop]);    
               if(fileList[loop].size() > 10)
               {
                     fileBuffer[loop].name.clear(); 
                     fileBuffer[loop].name.append( fileList[loop], 0 , 10);
                     fileBuffer[loop].name.append( 3, '.' );
                     }
               else
               {
                     fileBuffer[loop].name.clear();
                     fileBuffer[loop].name.append( fileList[loop], 0 , fileList[loop].size());
                     }
               fileBuffer[loop].file = isFile(fileBuffer[loop].path); 
    
               fileBuffer[loop].xFile = x;
               fileBuffer[loop].yFile = y;  
               fileBuffer[loop].xEndFile = x + 40;
               fileBuffer[loop].yEndFile = y + 50;                              
               y += 55;    
               if(y > 249)
               {
                    x += 108;
                    y = 10;
                    }
    
               }
    }
    int main(SceSize args, void *argp)
    {
        int x = 0;                            //storage for x coordinate
        int y = 0;                             //storage for y coordinate
        int mouseX = 10;                       //storage for mouse coordinates on x-as
        int mouseY = 10;                       //storage for mouse coordinates on y as
        int imageError = 0;                    //bool for error on image loading
        
        //*std::string fileBuffer[222];                //for the filelist
        
        //Pad init
        SceCtrlData pad;
        sceCtrlSetSamplingCycle(0);
        sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);   
        
        //init the garphics
        initGraphics();
        pspDebugScreenInit();
        pspDebugScreenClear();    
        
        //Image loading
        Image *iconExample = loadImageMemory(folderIcon , size_folderIcon);
        if(iconExample == NULL) imageError = 1;    
        Image *iconFolder  = loadImage("data/desktop/folder.PNG");
        if(iconFolder == NULL) imageError = 1;    
        Image *mouse       = loadImage("data/desktop/mouse.PNG");
        if(mouse == NULL) imageError = 1;  
        desktopBack = loadImage("data/desktop/wallpaper.PNG");
        if(desktopBack == NULL) imageError = 1;
        
        if(imageError)//if some images failed to load
        {
                      pspDebugScreenClear();
                      printf("error : failed to load an image:\n");
                      sceKernelSleepThread();
                      return 0;
                      } 
                      
        //printf("Images loaded\n"); 
                      
        //Load screenshot module
        LoadStartModule("data/screenshot.prx");    
    
        //get al files stored to a std::string of a directory
        
        fileBuffer[221].researchDir("ms0:/");
        //printf("filelist\n");
        
        while(1)
        { 
                //sceDisplayWaitVblankStart();
                blitImage(0 , 0 , desktopBack);//wallpaper   
                for(unsigned int loop = 0; loop < z; loop++ )
                { 
                     x = fileBuffer[loop].xFile;     
                     y = fileBuffer[loop].yFile;                      
                     if( fileBuffer[loop].file == 1)
                     {
                           blitImage(x , y ,iconExample);
                           }
                     else
                     {
                           blitImage(x , y ,iconFolder);
                           }    
                      y += 45;    
                      printg(x , y , fileBuffer[loop].name.c_str() , white);
                      }  
                      
                      blitImage(mouseX , mouseY , mouse);
                      flipScreen();
                      while(1)
                      {
                              sceCtrlReadBufferPositive(&pad, 1);	 
                              
                              if (pad.Lx < 80) //left
                              {
                                         mouseX -= 10;
                                         if(mouseX<0) mouseX = 460;
                                         break;
                                         }
                              if (pad.Lx > 175) //right
                              {
                                         mouseX += 10; 
                                         if(mouseX > 480) mouseX = 0;
                                         break;
                                         }
    	                      if (pad.Ly > 175) //down
    	                      {
                                         mouseY += 10;
                                         if(mouseY > 272) mouseY = 0;
                                         break;
                                         }
    	                      if (pad.Ly < 80) //up
    	                      {
                                         mouseY -= 10;
                                         if(mouseY<0) mouseY = 255;
                                         break;
                                         }									 
                              if(pad.Buttons & PSP_CTRL_HOME)
                              {
                                             sceKernelExitGame();
                                             }
                              if(pad.Buttons & PSP_CTRL_CROSS)
                              {
                                             int xLine = 0;
                                             int yLine = 0;
                                             for(unsigned int loop = 0; loop < z; loop++)
                                             {
                                                   if(mouseX >= fileBuffer[loop].xFile && mouseX <= fileBuffer[loop].xEndFile)
                                                   {
                                                             xLine = 1;
                                                             }
                                                   else xLine = 0;
                                                   if(mouseY >= fileBuffer[loop].yFile && mouseY <= fileBuffer[loop].yEndFile)
                                                   {
                                                             yLine = 1;
                                                             }
                                                   else yLine = 0;
                                                   if(yLine == 1 && xLine == 1)
                                                   {
                                                            if(fileBuffer[loop].file == 1)
                                                            {
                                                                 clearScreen(0xFFFFFF);
                                                                 printg(0,0,"No files supported , returning in 5 seconds", 0x0000FF);
                                                                 flipScreen();
                                                                 sceKernelDelayThread(5000000);
                                                                 break;
                                                                 }
                                                            else
                                                            {                                                                  
                                                                 fileBuffer[221].researchDir(fileBuffer[loop].path);
                                                                 break;
                                                                 }
                                                            }
                                                   }//end for
                                             }//end cross
                                                              
                        }//end while
                       
        }//end while
    
        
        sceKernelSleepThread();
        return 0;
    }


    I am not able to go to a folder , why?
    The first step works great , i see the files of the root and can move the mouse , but when i select something:
    file : shows the text and crashes
    folder : shows the text for files and carshes:s

  14. #5054
    QJ Gamer Bronze
    Points: 5.092, Level: 45
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Beiträge
    169
    Points
    5.092
    Level
    45
    Downloads
    0
    Uploads
    0

    Standard

    i´ve got a question that may be hard to answer.

    how do i use a .txt file for a map?
    please give some examples and please don´t flame me

    thanks

  15. #5055
    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 sony psp player
    i´ve got a question that may be hard to answer.

    how do i use a .txt file for a map?
    please give some examples and please don´t flame me

    thanks
    say your map file is like this:

    000010000
    000110000
    000111000
    000111001
    00...ect

    All the '0's are grass or whatever and '1's are something else. You would make a loader that gets a char from the file and do that how many times the file is in length. You would check each char to see is it was a number with isdigit(ch); (ch is the char that was read from the file)

    Just set the tiles accordingly or draw them, whatever
    Current releases:
    Icon Action Replacer v1.5- latest release
    Current projects:
    PSP C++ IDE - Currently v1.6
    RPG Paradise - Latest version at my website

  16. #5056
    QJ Gamer Bronze
    Points: 5.092, Level: 45
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Beiträge
    169
    Points
    5.092
    Level
    45
    Downloads
    0
    Uploads
    0

    Standard

    can you make an example that is nearly working?

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

    the way I do it isn't that reusable, it would be better to google 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

  18. #5058
    QJ Gamer Bronze
    Points: 5.092, Level: 45
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Beiträge
    169
    Points
    5.092
    Level
    45
    Downloads
    0
    Uploads
    0

    Standard

    can you find something on google?
    -= Double Post =-
    i have another question

    a string: abcdefghiklmnopqrstuvwxyz

    how do i get the letters "cdefgh" out of this string?
    Geändert von sony psp player (06-15-2007 um 12:55 PM Uhr) Grund: Automerged Doublepost

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

    you mean find them specifically or cut them out of 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

  20. #5060
    QJ Gamer Bronze
    Points: 5.092, Level: 45
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Beiträge
    169
    Points
    5.092
    Level
    45
    Downloads
    0
    Uploads
    0

    Standard

    i have the beginning position and the end position and i wanna have them in another string, while the first string isn´t changed

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

    Do get those specifically you would do this:

    Code:
    int main()
    {
         char *str = "abcdefghiklmnopqrstuvwxyz";
         char specific_data[10];
         char *ptr;
         ptr = strstr(str,"cdefgh"); /*strstr returns the pointer to where "cdefgh" starts*/
         strncpy(specific_data,ptr,6); /*copys "cdefgh"  to string specific_data*/
          //specific_data now holds "cdefgh" and str remains the same
          return 0;
    }
    Current releases:
    Icon Action Replacer v1.5- latest release
    Current projects:
    PSP C++ IDE - Currently v1.6
    RPG Paradise - Latest version at my website

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

    sony_psp_player - There's multiple ways, but you still haven't answered the question. Would you like to be able to call a function saying:

    if "cdefgh" is found in string "abcdefghijklmnopqrstuvwx yz" then ...

    Or would you just like to take out the 3rd,4th,5th,6th,7th and 8th element out of an array of characters...

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


  23. #5063
    QJ Gamer Bronze
    Points: 7.047, Level: 55
    Level completed: 49%, Points required for next Level: 103
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Beiträge
    144
    Points
    7.047
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    For maps you're better off with serialization. (Search on google)
    Adrahil - Software architect and specialist in Reverse Engineering.
    Spoiler for Guilt of a Dev:
    17:17 < InsertWittyName> Can't pin user error on a dev ;)
    17:18 < InsertWittyName> Lesson learnt on both sides I would say.
    17:18 < InsertWittyName> You learnt to treat the end-user as a retarded fish.
    17:18 < InsertWittyName> They learnt to read readme's ;)

    Spoiler for me:
    17:12 <+dot_blank> are you the long haired pimp ;)

  24. #5064
    QJ Gamer Bronze
    Points: 5.092, Level: 45
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Beiträge
    169
    Points
    5.092
    Level
    45
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von SG57
    sony_psp_player - There's multiple ways, but you still haven't answered the question. Would you like to be able to call a function saying:

    if "cdefgh" is found in string "abcdefghijklmnopqrstuvwx yz" then ...

    Or would you just like to take out the 3rd,4th,5th,6th,7th and 8th element out of an array of characters...
    i wanna take out the 3rd,4th,5th,6th,7th and 8th, so if the string was

    "abcdefghijkl"

    it would take out "cdefgh"


    "ajsdafhdjajdkfja"

    it would take out "sdafhd"

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

    Ok. I suggest you read up on arrays and write it yourself, but if you get stuck or whatever, use this as a reference.
    Code:
    int grabber(char *dest_string, const char *source_string) { // for lack of a better function name
        static const MINIMUM_STRING_SIZE = 8;
        static const NUM_CHARS_TO_EXTRACT = 6;
        
        if(strlen(source_string) < MINIMUM_STRING_SIZE || sizeof(dest_string) < NUM_CHARS_TO_EXTRACT+1 /* compensate for '\0' */)
            return 0; // failure :(
        
        dest_string[0] = source_string[2];
        dest_string[1] = source_string[3];
        dest_string[2] = source_string[4];
        dest_string[3] = source_string[5];
        dest_string[4] = source_string[6];
        dest_string[5] = source_string[7];
        dest_string[6] = '\0'; // not sure whether this is automatically added or not, so it's a safety percaution
        
        return 1; // success :)
    }
    I haven't messed with strlen or sizeof in a long time, so I'm not sure whether strlen includes the '\0' and if sizeof reserves space for the '\0', so sorry ifthe numbering is off a little (a quick fix if so).

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


  26. #5066
    QJ Gamer Bronze
    Points: 7.047, Level: 55
    Level completed: 49%, Points required for next Level: 103
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Beiträge
    144
    Points
    7.047
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    Wow, you really like to make things complicated, SG57..... Just use strncpy ;)
    Code:
    strncpy(dest, alphabet+2, 6);
    Will yield "cdefgh" if alphabet is "abcdefghijklmnopqrstuvwx yz"

    Just don't forget to memset(dest, 0, XXX);, where XXX is the size of the dest buffer (declared as char dest[XXX];), and remember to make a buffer big enough so that there is a trailing 0 left.
    Adrahil - Software architect and specialist in Reverse Engineering.
    Spoiler for Guilt of a Dev:
    17:17 < InsertWittyName> Can't pin user error on a dev ;)
    17:18 < InsertWittyName> Lesson learnt on both sides I would say.
    17:18 < InsertWittyName> You learnt to treat the end-user as a retarded fish.
    17:18 < InsertWittyName> They learnt to read readme's ;)

    Spoiler for me:
    17:12 <+dot_blank> are you the long haired pimp ;)

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

    I like manual conversions, it gives me a sense of safety for some reason.

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


  28. #5068
    QJ Gamer Bronze
    Points: 7.047, Level: 55
    Level completed: 49%, Points required for next Level: 103
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Beiträge
    144
    Points
    7.047
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von SG57
    I like manual conversions, it gives me a sense of safety for some reason.
    Manual CONVERSIONS? :/ There are no "conversions" here... Moreover, there is no possible WAY in which you'd be able to outperform standard libc functions... I bet you'd not be able to understand completely the operation of functions such as these:
    Code:
    char *
    strncpy(char *dst, const char *src, size_t n)
    {
            if (n != 0) {
                    char *d = dst;
                    const char *s = src;
    
                    do {
                            if ((*d++ = *s++) == 0) {
                                    while (--n != 0)
                                            *d++ = 0;
                                    break;
                            }
                    } while (--n != 0);
            }
            return (dst);
    }
    (from OpenBSD source code repository for libc)
    Well, to come back to the subject, your method is really unoptimized and is not made for a dynamic map loading, as the lengths are static. With strncpy, it is much easier to split a string into different parts...
    Adrahil - Software architect and specialist in Reverse Engineering.
    Spoiler for Guilt of a Dev:
    17:17 < InsertWittyName> Can't pin user error on a dev ;)
    17:18 < InsertWittyName> Lesson learnt on both sides I would say.
    17:18 < InsertWittyName> You learnt to treat the end-user as a retarded fish.
    17:18 < InsertWittyName> They learnt to read readme's ;)

    Spoiler for me:
    17:12 <+dot_blank> are you the long haired pimp ;)

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

    why isnt it

    Code:
    char *
    strncpy(char *dst, const char *src, size_t n)
    {
            if (n != 0) {
                    char *d = dst;
                    const char *s = src;
    
                
                     if ((*d++ = *s++) == 0) {
                                while (--n != 0)
                                       *d++ = 0;
                                 }  
            }
            return (dst);
    }

  30. #5070
    QJ Gamer Bronze
    Points: 7.047, Level: 55
    Level completed: 49%, Points required for next Level: 103
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Beiträge
    144
    Points
    7.047
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    Uhm... You're only copying one char here, no? (No while() loop to do (*d++ = *s++))... I think you meant "while((*d++ = *s++)...", but tbh, I think the code in the repository is the way they found it to be a good compromise between portability, speed and readability. :)

    (There were a few comments in the original code, but i didn't bother to copy/paste them ;) )
    Adrahil - Software architect and specialist in Reverse Engineering.
    Spoiler for Guilt of a Dev:
    17:17 < InsertWittyName> Can't pin user error on a dev ;)
    17:18 < InsertWittyName> Lesson learnt on both sides I would say.
    17:18 < InsertWittyName> You learnt to treat the end-user as a retarded fish.
    17:18 < InsertWittyName> They learnt to read readme's ;)

    Spoiler for me:
    17:12 <+dot_blank> are you the long haired pimp ;)


 

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 .