Salem_c's Profile User Rating: ****-

Reputation: 1645 Grandmaster
Group:
Mentors
Active Posts:
3,121 (2.01 per day)
Joined:
30-May 10
Profile Views:
36,424
Last Active:
User is offline Yesterday, 11:03 PM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0
Icon   Salem_c has not set their status

Posts I've Made

  1. In Topic: Webbot and data analyzing

    Posted 28 Aug 2014

    Let's start with a different question - what specifically about PHP is making your job very hard or impossible?

    Yes you can use Python / Perl / C++ / whatever, but the real trick is
    a) do you know those languages well enough?
    b) are you willing to spend the time learning them?
    c) what kind of libraries / language features are available for 'web access'?

    FWIW, I use Perl for this kind of stuff (and text processing in general), for example,
    http://search.cpan.o...WW/Mechanize.pm
    http://search.cpan.o...HTML-Tree-5.03/
    cpan has over 3000 modules dealing with all aspects of HTML, I'm sure you'll find something to like.
  2. In Topic: File handling in c++

    Posted 27 Aug 2014

    45 inFile.open(inputFileName); // Opening the file
    46 editFile.open(inputFileName, ios::ate);
    Open a different filename then.

    When you've written the new file, close both of them, then do the following
    - delete the old one (or rename it to say sample2.txt.bak
    - rename the temporary file as sample2.txt
  3. In Topic: [c++] SDL program == slow working insect

    Posted 26 Aug 2014

    Allow me to indent your awful code.
    #include "SDL/SDL.h"
    #include <string>
    #include <iostream>
    
    
    const int SCREEN_WIDTH = 1240;
    const int SCREEN_HEIGHT = 800;
    const int SCREEN_BPP = 32;
    int stanje(0);
    SDL_Surface *sjc = NULL;
    SDL_Surface *kom = NULL;        //commands
    SDL_Surface *ozadje = NULL;
    SDL_Surface *kristjan = NULL;
    SDL_Surface *kr22 = NULL;
    SDL_Surface *kr33 = NULL;
    SDL_Surface *skok = NULL;
    SDL_Surface *noob = NULL;       // fail
    SDL_Surface *plag = NULL;       ///play again
    SDL_Surface *e244 = NULL;
    SDL_Surface *idiot = NULL;
    SDL_Surface *screen = NULL;
    SDL_Event event;
    
    
    //voids from lazy foo
    
    SDL_Surface *load_image(std::string filename)
    {
      SDL_Surface *loadedImage = NULL;
    
      SDL_Surface *optimizedImage = NULL;
    
      loadedImage = SDL_LoadBMP(filename.c_str());
    
      if (loadedImage != NULL) {
        optimizedImage = SDL_DisplayFormat(loadedImage);
    
        SDL_FreeSurface(loadedImage);
        if (optimizedImage != NULL) {
          //Map the color key
          Uint32 colorkey = SDL_MapRGB(optimizedImage->format, 0, 0xFF, 0xFF);
    
          //Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent
          SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY, colorkey);
        }
      }
      return optimizedImage;
    }
    
    void apply_surface(int x, int y, SDL_Surface * source, SDL_Surface * destination)
    {
      //Make a temporary rectangle to hold the offsets
      SDL_Rect offset;
    
      //Give the offsets to the rectangle
      offset.x = x;
      offset.y = y;
    
      //Blit the surface
      SDL_BlitSurface(source, NULL, destination, &offset);
    }
    
    int main(int argc, char *args[])
    {
      bool quit = false;
      //Initialize all SDL subsystems
      if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {
        return 1;
      }
    
      screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
      if (screen == NULL) {
        return 1;
      }
    
      SDL_WM_SetCaption("#ski jumps challenge", NULL);
      //picture of produser
      sjc = load_image("IA.bmp");
      apply_surface(0, 0, ozadje, screen);
      if (SDL_Flip(screen) == -1) {
        return 1;
      }
    
      SDL_Delay(3000);;
      //picture of this game
      sjc = load_image("sjc.bmp");
      apply_surface(0, 0, ozadje, screen);
      if (SDL_Flip(screen) == -1) {
        return 1;
      }
    
      SDL_Delay(3000);;
    
    
    
      while (quit == false)         //1. }
      {
        while (SDL_PollEvent(&event)) { //2. }
          if (event.type == SDL_KEYDOWN)  //3. }
          {
            //picture of commands
            kom = load_image("kom.bmp");
            SDL_FreeSurface(sjc);
            apply_surface(0, 0, kom, screen);
            if (SDL_Flip(screen) == -1) {
              return 1;
            }
            while (quit == false)   //1. }
            {
              int x(88);
              int y(73);
    
              while (SDL_PollEvent(&event)) { //2. }
                if (event.type == SDL_KEYDOWN)  //3. }
                {
                  //character(==kr,kr22,kr33) and blacgraund(==ozadje) picture)
                  ozadje = load_image("ozadje.bmp");
                  SDL_FreeSurface(kom);
                  apply_surface(0, 0, ozadje, screen);
                  kristjan = load_image("kr.bmp");
                  apply_surface(x, y, kristjan, screen);
                  if (SDL_Flip(screen) == -1) {
                    return 1;
                  }
                  while (quit == false) //1. }
                  {
                    while (SDL_PollEvent(&event)) {
                      if (event.type == SDL_KEYDOWN) {
                        switch (event.key.keysym.sym) {
                        case SDLK_SPACE:
                          stanje + 1;
                        }
                      }
                    }
                    while (quit == false) //1. }
                    {
                      int poz(0);   //pozicija
                      //flying of character
                      while (stanje == 1) {
                        //95, 85
                        x == 95;
                        y == 84;
                        SDL_Delay(40);
                        x == 104;
                        y == 99;
                        SDL_Delay(40);
                        x == 108;
                        y == 106;
                        SDL_Delay(40);
                        x == 112;
                        y == 113;
                        SDL_Delay(40);
                        x == 115;
                        y == 119;
                        SDL_Delay(40);
                        x == 119;
                        y == 125;
                        SDL_Delay(40);
                        x == 123;
                        y == 132;
                        SDL_Delay(40);
                        x == 127;
                        y == 139;
                        SDL_Delay(40);
                        x == 131;
                        y == 146;
                        SDL_Delay(40);
                        x == 137;
                        y == 156;
                        SDL_Delay(40);
                        x == 141;
                        y == 163;
                        SDL_Delay(40);
                        x == 144;
                        y == 171;
                        SDL_Delay(40);
                        x == 150;
                        y == 179;
                        SDL_Delay(40);
                        x == 154;
                        y == 187;
                        SDL_Delay(40);
                        x == 159;
                        y == 195;
                        SDL_Delay(40);
                        x == 164;
                        y == 204;
                        SDL_Delay(40);
                        x == 169;
                        y == 212;
                        SDL_Delay(40);
                        x == 174;
                        y == 220;
                        SDL_Delay(40);
                        x == 178;
                        y == 228;
                        SDL_Delay(40);
                        x == 183;
                        y == 236;
                        SDL_Delay(40);
                        x == 187;
                        y == 234;
                        SDL_Delay(40);
                        x == 193;
                        y == 253;
                        SDL_Delay(40);
                        x == 198;
                        y == 261;
                        SDL_Delay(40);
                        x == 204;
                        y == 272;
                        SDL_Delay(40);
                        x == 209;
                        y == 281;
                        SDL_Delay(40);
                        x == 214;
                        y == 290;
                        SDL_Delay(40);
                        x == 219;
                        y == 299;
                        SDL_Delay(40);
                        x == 225;
                        y == 309;
                        SDL_Delay(40);
                        x == 231;
                        y == 319;
                        SDL_Delay(40);
                        x == 237;
                        y == 329;
                        SDL_Delay(40);
                        x == 243;
                        y == 339;
                        SDL_Delay(40);
                        x == 249;
                        y == 349;
                        SDL_Delay(40);
                        x == 258;
                        y == 360;
                        SDL_Delay(40);
                        x == 263;
                        y == 363;
                        SDL_Delay(40);
                        x == 269;
                        y == 365;
                        SDL_Delay(40);
                        x == 279;
                        y == 368;
                        SDL_Delay(40);
                        x == 289;
                        y == 371;
                        SDL_Delay(40);
                        x == 299;
                        y == 373;
                        SDL_Delay(40);
                        x == 310;
                        y == 376;
                        SDL_Delay(40);
                        x == 321;
                        y == 380;
                        SDL_Delay(40);
                        x == 330;
                        y == 382;
                        SDL_Delay(40);
                        if (SDL_Flip(screen) == -1) {
                          return 1;
                        }
                        while (quit == false) //1. }
                        {
                          if (poz == 0) {
                            //if you fail
                            SDL_FreeSurface(kristjan);
                            kr22 = load_image("k5.bmp");
                            apply_surface(395, 388, kr22, screen);
                            SDL_Delay(2000);
                            kr22 = load_image("loos.bmp");
                            apply_surface(0, 0, kr22, screen);
                            SDL_Delay(2000);
                            if (SDL_Flip(screen) == -1) {
                              return 1;
                            }
                          }
                        }
                      }
                      while (quit == false) //1. }
                      {
                        while (SDL_PollEvent(&event)) {
                          if (event.type == SDL_KEYUP) {
                            poz + 1;
                            switch (event.key.keysym.sym) {
                            case SDLK_SPACE:
                              stanje + 1;
                            }
                          }
                        }
                        while (quit == false) //1. }
                        {
                          while (stanje == 1) {
                            if (y <= 363) {
                              SDL_FreeSurface(kristjan);
                              kr22 = load_image("k5.bmp");
                              apply_surface(395, 388, kr22, screen);
                              SDL_Delay(2000);
                              kr22 = load_image("loos.bmp");
                              apply_surface(0, 0, kr22, screen);
                              SDL_Delay(2000);
                              if (SDL_Flip(screen) == -1) {
                                return 1;
                              }
                            }
                            else if (y >= 363) {
                              int a(395);
                              int b(385);
                              SDL_FreeSurface(kristjan);
                              kr22 = load_image("k2.bmp");
                              apply_surface(394, 382, kr22, screen);
                              SDL_Delay(500);
                              SDL_FreeSurface(kr22);
                              kr33 = load_image("k3.bmp");
                              apply_surface(a, b, kr33, screen);
                              if (SDL_Flip(screen) == -1) {
                                return 1;
                              }
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              a + 5;
                              SDL_Delay(40);
                              if (SDL_Flip(screen) == -1) {
                                return 1;
                              }
                              kr22 = load_image("k4.bmp");
                              apply_surface(a, b, kr22, screen);
                              while (quit == false) //1. }
                                if (SDL_Flip(screen) == -1) {
                                  return 1;
                                }
                              {
                                while (SDL_PollEvent(&event)) {
                                  if (event.type == SDL_KEYUP) {
                                    poz + 1;
                                    switch (event.key.keysym.sym) {
                                    case SDLK_LEFT:
                                      stanje == 3;
                                    case SDLK_RIGHT:
                                      stanje == 3;
                                    }
                                  }
                                }
                                while (quit == false) //1. }
                                {
                                  if (SDL_Flip(screen) == -1) {
                                    return 1;
                                  }
                                  if (stanje == 3) {
                                    kr22 = load_image("k2.bmp");
                                    apply_surface(812, 638, kr22, screen);
                                    SDL_Delay(200);
                                    kr22 = load_image("win.bmp");
                                    apply_surface(0, 0, kr22, screen);
                                    SDL_Delay(1000);
                                    if (SDL_Flip(screen) == -1) {
                                      return 1;
                                    }
                                    //winers music
                                    system("Avseniki - Planica.mp3");
    
                                  }
                                }
                              }
                              SDL_Quit();
                              return 0;
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    
    

    THIRTEEN - count 'em!
    13 closing braces in a row - your code is a nested nightmare.

    Next, compile with more warnings.
    $ g++ -Wall -Wno-switch -c bar.cpp
    bar.cpp: In function ‘int main(int, char**)’:
    bar.cpp:131:33: warning: statement has no effect [-Wunused-value]
    bar.cpp:141:28: warning: statement has no effect [-Wunused-value]
    bar.cpp:142:28: warning: statement has no effect [-Wunused-value]
    bar.cpp:144:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:145:28: warning: statement has no effect [-Wunused-value]
    bar.cpp:147:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:148:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:150:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:151:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:153:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:154:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:156:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:157:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:159:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:160:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:162:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:163:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:165:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:166:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:168:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:169:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:171:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:172:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:174:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:175:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:177:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:178:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:180:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:181:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:183:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:184:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:186:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:187:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:189:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:190:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:192:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:193:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:195:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:196:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:198:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:199:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:201:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:202:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:204:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:205:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:207:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:208:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:210:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:211:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:213:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:214:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:216:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:217:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:219:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:220:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:222:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:223:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:225:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:226:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:228:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:229:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:231:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:232:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:234:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:235:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:237:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:238:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:240:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:241:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:243:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:244:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:246:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:247:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:249:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:250:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:252:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:253:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:255:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:256:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:258:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:259:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:261:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:262:29: warning: statement has no effect [-Wunused-value]
    bar.cpp:288:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:291:37: warning: statement has no effect [-Wunused-value]
    bar.cpp:324:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:326:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:328:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:330:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:332:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:334:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:336:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:338:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:340:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:342:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:344:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:346:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:348:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:350:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:352:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:354:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:356:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:358:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:360:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:362:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:364:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:366:32: warning: statement has no effect [-Wunused-value]
    bar.cpp:380:40: warning: statement has no effect [-Wunused-value]
    bar.cpp:383:46: warning: statement has no effect [-Wunused-value]
    bar.cpp:385:46: warning: statement has no effect [-Wunused-value]
    
    

    The reason your code doesn't seem to do anything for a lot of the time is because it isn't doing anything for a lot of the time.

    Lines 140 to 260 consist of 41 consecutive Delay() calls, with a total elapsed time of over 1.5 seconds of doing precisely NOTHING.

    Then there is another huge block of nothing later on.

                            kr22 = load_image("k5.bmp");
                            apply_surface(395, 388, kr22, screen);
                            SDL_Delay(2000);
                            kr22 = load_image("loos.bmp");
    
    

    If you want better performance, load all your resources exactly ONCE at program startup.
    Loading every time is bad enough.
    Loading different resources into the same variable is worse.

    > while (SDL_PollEvent(&event))
    You should have exactly ONE of these (you've got 5 of them).

    What should be inside your event loop is one (or more) of these.
    https://en.wikipedia...e-state_machine

    The wall of text in upper case doesn't help either.
    http://www.catb.org/....html#writewell
  4. In Topic: c++ aviriff.h error C2146

    Posted 25 Aug 2014

    Is that the first error message you get, or just the first one you don't understand?

    Also, posting a few lines before the actual error line helps. Error lines are where a problem was detected. Often the root cause is a problem on the previous line.

    Solve errors in order - later errors are often the result of the compiler incorrectly guessing how to 'fix' the code so it can carry on compiling.

    > I got it from the web for learning purposes.
    Telling us where you got it would at least allow us the option to fetch the code and inspect (or even try) what you're trying to do.
  5. In Topic: Any error in my coding?

    Posted 25 Aug 2014

    > If it's wrong then how come it isn't giving me any error or even a warning?
    You don't get a warning, because it's a valid C expression.

    There are all sorts of valid expressions, it's just a question of whether it's the RIGHT expression for the thing you're trying to do.

    The mere fact it compiles is irrelevant - we all know it compiles.

    The real issue is that you think (x,y,r) tests all three numbers to be within a given range, and we're all telling you that it doesn't.

    > If I really don't write the 'while' statement as you and others keep saying then it gives me bunch of errors!
    At this point, showing us what you tried and the ACTUAL error messages would be a good idea. Your comment is about as useless as phoning a doctor and all you can say is "it hurts". Post some evidence we can all work with.

My Information

Member Title:
void main'ers are DOOMED
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Programming Languages:
C, C++, Perl, awk, various assemblers

Contact Information

E-mail:
Private

Comments

Page 1 of 1
  1. Photo

    fromTheSprawl Icon

    07 Sep 2012 - 02:38
    Please read my thread. I kid! Just want to say your forum avatar is awesome. ^^
  2. Photo

    Salem_c Icon

    26 Dec 2010 - 01:36
    Do not PM me for 1:1 support, or to try to get me to read your threads.
Page 1 of 1