As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
We're funding a new Acquisitions Incorporated series on Kickstarter right now! Check it out at https://www.kickstarter.com/projects/pennyarcade/acquisitions-incorporated-the-series-2

PA Programming Thread - The Best Servers Are The Ones You Don't Use

1434446484963

Posts

  • ASimPersonASimPerson Cold... and hard.Registered User regular
    edited February 2011
    MKR wrote: »
    ASimPerson wrote: »
    Echo wrote: »
    I used to write IRC stuff in TCL back when I was a l33t d00d.

    Then I grew hair on my balls and got interested in girls.

    Were you one of the 10 people besides me who actually used XiRCON?

    I knew a few people who used it. All of them were terrifying people.

    In fairness, it wasn't that outdated when I was most active on IRC (1998-2003ish), but the channels I hung out also had their own script that ran on top of it that made all super leet.

    Ah, high school.

    ASimPerson on
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited February 2011
    ASimPerson wrote: »
    Here's an easier question: What is the correct way to properly do command-line interactive programs in C. I feel like the way I normally do it is incredably fragile...

    Here was I was working on tonight. It's homework, where we are simulating an ALU. The test program here isn't really the main point of the project, so I don't feel bad asking about it. scanf is such a house of cards sometimes.
    int main(void) {
        RegisterFilePtr rf = registerFile_initialize();
        RegisterPtr status = register_initialize();
        Alu alu = alu_initialize(rf, status);
        printf("%s", registerFile_toString(rf));
    
        int running = TRUE;
        int input = 0;
        int value = 0;
        int error = NO_ERROR;
    
        while (running == TRUE) {
            printf("What would you like to do?\n");
            printf("\t1: Print register file.\n");
            printf("\t2: Set a register.\n");
            printf("\t3: Perform an ALU operation.\n");
            printf("\t0: Exit.\n:");
            //read input
            if (scanf("%i", &input) == 1){
                //determine what to do
                switch (input){
                    //Exit
                    case 0: running = FALSE; break;
                    //Print register file
                    case 1: printf("%s", registerFile_toString(rf)); break;
                    //Set register
                    case 2:
                        //get register choice
                        printf("Which register to set?\n:");
                        if (scanf("%i", &input) != 1){printf("What?\n"); break;}
                        //get register value
                        printf("\nInput new value.\n:");
                        if (scanf("%i", &value) != 1){printf("What?\n"); break;}
                        //Perform register setting
                        error = registerFile_putRegValue(rf, (uchar) input,
                                                         (uchar) value);
                        //report results
                        if (error == NO_ERROR){
                            printf("\nRegister $%X set to %04X\n", input, value);
                        } else {
                            printf("\nError!\n");
                        }
                        break;
                    case 3:
                        //get operation choice
                        printf("Which ALU operation would you like to perform?\n");
                        printf("ADD:\t0x0\t(A+B->R)\n");
                        printf("SUB:\t0x1\t(A-B->R)\n");
                        printf("NEG:\t0x2\t(-A->R)\n");
                        printf("MUL:\t0x3\t(A*B->[R8,R9])\n");
                        printf("DIV:\t0x4\t(A/B->RA, A%B->RB)\n");
                        printf("AND:\t0x5\t(A&B->R)\n");
                        printf("OR:\t0x6\t(A|B->R)\n");
                        printf("XOR:\t0x7\t(A^B->R)\n");
                        printf("NOT:\t0x8\t(~A->R)\n");
                        printf("SFL:\t0x9\t(A<<1->R)\n");
                        printf("SFR:\t0xA\t(A>>1->R)\n");
                        if (scanf("%i", &input) != 1){printf("What?\n"); break;}
                        //get first operand
                        printf("Which register is first operand?\n:");
                        if (scanf("%i", &value) != 1){
                            printf("What?\n"); break;
                        } else {
                            error = alu_loadFromReg(alu, value, $RALUA);
                            if (error == NO_ERROR){
                                printf("\nLoaded ALU register A with value");
                                printf(" in register $R%X\n", value);
                            } else {
                                printf("\nError(%X)\n", error);
                            }
                        }
                        //get second operand
                        int choice;
                        printf("Load second operand from register (0)\n");
                        printf("Or load an immediate value? (1)\n:");
                        if (scanf("%i", &choice) != 1){printf("What?"); break;}
    
                        //Load B from register
                        if (choice == 0){
                            printf("Which register is second operand?\n:");
                            if (scanf("%i", &value) != 1){
                                printf("What?\n"); break;
                            } else {
                                error = alu_loadFromReg(alu, (uchar) value, $RALUB);
                                if (error == NO_ERROR){
                                    printf("\nLoaded ALU register B with value");
                                    printf(" in register $R%X\n\n", value);
                                } else {
                                    printf("\nError(%X)\n", error);
                                }
                            }
                        } else {//Load B from immediate
                            printf("What value for second operand?\n:");
                            if (scanf("%i", &value) != 1){
                                printf("What?\n"); break;
                            } else {
                                error = alu_loadFromImmediate(alu, (ushort) value);
                                if (error == NO_ERROR){
                                    printf("\nLoaded ALU register B with value");
                                    printf("%04X\n\n", value);
                                } else {
                                    printf("\nError(%X)\n", error);
                                }
                            }
                        }
                        alu_operation(alu, input);
                        printf("RegA: %04X\n", alu_getRegValue(alu, $RALUA, &error));
                        printf("RegB: %04X\n", alu_getRegValue(alu, $RALUB, &error));
                        printf("RegR: %04X\n", alu_getRegValue(alu, $RALUR, &error));
                }
            } else {
                //clear the input buffer
                while (getchar() != '\n'){};
            }
        }
    }
    

    scanf() tends to be a house of cards mainly due to its vulnerabilities more than anything else. Anyway, I don't really see anything wrong here (other than the lack of a default case in your switch statement). I would probably abstract some of those larger switch cases into functions though.

    I gotta say, though, if you actually had to write this out what a huge waste of time. The focus should be on the ALU part. Much easier not worry about interactivity and just let you parse a file or something. Geez.

    I did not, strictly speaking, have to do it interactively. There was the option to hard-code a demo of the ALU operations. It was an option to do it this way, so I did it.

    Monkey Ball Warrior on
    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • templewulftemplewulf The Team Chump USARegistered User regular
    edited February 2011
    Hey, does anyone have any recommendations for guides to using SOAP RPC with PHP?

    I think the web service is already provided to me (they sent a WSDL and a service URL), so I'll just have to develop the app side of it.

    templewulf on
    Twitch.tv/FiercePunchStudios | PSN | Steam | Discord | SFV CFN: templewulf
  • cmsamocmsamo Registered User regular
    edited February 2011
    OK - another C++/MFC question:

    If I have a class, and I want to create many objects and store them in a dynamic array, how do I set it up? I read in a list of files in a directory on initialisation, so I know that for example I may have 50 files, and what I want to do is read each file into a class, which creates an object. I then want to be able to store each object that I've created in an array of objects, so I can recall them all later. What I can't seem to do is declare a dynamic array of objects based on the number of files I've read in to start with...

    cmsamo on
    steam_sig.png
  • ecco the dolphinecco the dolphin Registered User regular
    edited February 2011
    cmsamo wrote: »
    OK - another C++/MFC question:

    If I have a class, and I want to create many objects and store them in a dynamic array, how do I set it up? I read in a list of files in a directory on initialisation, so I know that for example I may have 50 files, and what I want to do is read each file into a class, which creates an object. I then want to be able to store each object that I've created in an array of objects, so I can recall them all later. What I can't seem to do is declare a dynamic array of objects based on the number of files I've read in to start with...

    Do you mean something like....
    
    #include <vector>
    using std::vector;
    
    class tFileInfo; // Contains file information that you wish to store
    
    typedef std::vector< tFileInfo > tFileInfoVector;
    
    void initFileList( tFileInfoVector& rFileInfoVector )
    {
      while( stillFiles )
      {
        rFileInfoVector.push_back( tFileInfo( /* constructor */ ) );
      }
    }
    
    int main( int argc, char * argv[] )
    {
      tFileInfoVector currentFiles;
    
      initFileLIst( currentFiles );
    
      for( tFileInfoVector::iterator fileIter = currentFiles.begin(); fileIter != currentFiles.end(); ++fileIter )
      {
        tFileInfo& rFile = *fileIter;
        // Do something with rFile
      }
    
      // or can access like an array
      for( unsigned fileIndex = 0; fileIndex < currentFiles.size(); ++fileIndex )
      {
        tFileInfo& rFIle = currentFiles[fileIndex];
        // Do something with rFile
      }
    }
    
    

    That'll be a generic C++ way of doing it.

    The more C oriented way would be to dynamically allocate an array:
    tFileInfo *pFileArray = new tFileInfo[ NUM_OF_FILES ];
    for( unsigned fileIndex = 0; fileIndex < NUM_OF_FILES; ++fileIndex )
    {
      // operate on stuff
    }
    delete[] pFileArray; // Free allocated memory
    

    An MFC specific way involves using CArray.

    Each has its own advantages/disadvantages, depending on situation.

    Mostly recommend using std::vector, though.

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • cmsamocmsamo Registered User regular
    edited February 2011
    Ya Ecco that vector approach looks like the kind of thing I need to do. It's not actually files that I am storing, it's a whole bunch of filepaths. The info I need to break out is the different parts of the filename (which all have a meaning in various other places).

    I'll give it a shot but I think what you've desribed will suit me perfectly :) Thanks

    cmsamo on
    steam_sig.png
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited February 2011
    Is there any such thing as a Folder object in Python? Analogous to the File object?

    Jasconius on
  • BarrakkethBarrakketh Registered User regular
    edited February 2011
    Jasconius wrote: »
    Is there any such thing as a Folder object in Python? Analogous to the File object?
    Not that I know of. I don't see an obvious need for one, either.

    Barrakketh on
    Rollers are red, chargers are blue....omae wa mou shindeiru
  • agoajagoaj Top Tier One FearRegistered User regular
    edited February 2011
    Well, trying to do something simple/quickly is giving me problems again.

    I've got characters walking down an alley, and I've set up a trapezoid they can walk in. To the characters it's a 1024 x 1024 field, I use this algorithm to scale that into actual screen coordinates.
    *ratioX = x / (PlaneMaxX - PlaneMinX);
    	*ratioY = ( y / (PlaneMaxY - PlaneMinY));
    	float minX = ((Points[0].x - Points[2].x) * (1- *ratioY)) + Points[2].x;
    	float maxX = ((Points[3].x - Points[1].x) * *ratioY) + Points[1].x;
    	*displayX = (*ratioX * (maxX - minX)) + minX;
    	*displayY = (*ratioY * (PlaneBottom - PlaneTop)) + PlaneTop;
    
    The problem with this is that lines curve like crazy. What I remember about perspective in art class is that straight lines are straight in any perspective, so what am I doing wrong in my approach?

    agoaj on
    ujav5b9gwj1s.png
  • EchoEcho ski-bap ba-dapModerator mod
    edited February 2011
    ASimPerson wrote: »
    Echo wrote: »
    I used to write IRC stuff in TCL back when I was a l33t d00d.

    Then I grew hair on my balls and got interested in girls.

    Were you one of the 10 people besides me who actually used XiRCON?

    Now that's a name I haven't heard in years.

    Worked on a script package called Kallisti.

    Echo on
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    edited February 2011
    No, they definitely shouldn't curve, barring weird projections (fisheye, etc). How are you drawing them? The easiest way would be to translate the start/end coordinates to whatever your view space is and then just draw a line between those two points

    Phyphor on
  • agoajagoaj Top Tier One FearRegistered User regular
    edited February 2011
    Yeah, if I just draw a line between the 2 points it works fine. But if I break it up into steps it curves, which makes tracing that line to do hit detection or moving characters hard.

    agoaj on
    ujav5b9gwj1s.png
  • Grey PaladinGrey Paladin Registered User regular
    edited February 2011
    I need advice on choosing a programming language to study. I have rudimentary knowledge of Assembly and a fair grasp of Java, along with design principles and patterns. I have little difficulty with most programs that can be interacted with from a command line, but I seriously struggle with GUIs and graphics (to the point where I have no idea how most of Java's graphical classes/functions actually work).

    I wish to write a fairly simple grid-based, 2D, turn-based tactical RPG, in the style of X-COM or Final Fantasy Tactics. Which language should I learn and use for that purpose?

    Grey Paladin on
    "All men dream, but not equally. Those who dream by night in the dusty recesses of their minds wake in the day to find that it was vanity; but the dreamers of the day are dangerous men, for they may act their dream with open eyes to make it possible." - T.E. Lawrence
  • FremFrem Registered User regular
    edited February 2011
    I need advice on choosing a programming language to study. I have rudimentary knowledge of Assembly and a fair grasp of Java, along with design principles and patterns. I have little difficulty with most programs that can be interacted with from a command line, but I seriously struggle with GUIs and graphics (to the point where I have no idea how most of Java's graphical classes/functions actually work).

    I wish to write a fairly simple grid-based, 2D, turn-based tactical RPG, in the style of X-COM or Final Fantasy Tactics. Which language should I learn and use for that purpose?

    Really, for that sort of stuff, it's what libraries you use that matter more than the language. Java isn't the greatest language for writing games in, but millions of Minecraft players don't seem to care. It'd probably work fine.

    This being said, I'm not a huge fan of Java. I'd probably look at LÖVE (Lua) or maybe PyGame or Cocos2D (Python). XNA or Unity3D are good if you want to write some C#.

    Frem on
  • Randall_FlaggRandall_Flagg Registered User regular
    edited February 2011
    hey programming thread, programming on windows is pretty sucky, and my current laptop is super old and falling apart, so I'm looking to buy a new laptop to run linux on

    do you guys have any recommendations for a really cheap laptop/netbook that will work fine with linux

    Randall_Flagg on
  • Ethereal IllusionEthereal Illusion Registered User regular
    edited February 2011
    So keeping up with my promise, the game I was working on is complete with much help from you all, specifically the AI pathfinding.

    Unity game link is here: http://www.kongregate.com/games/celticconundrum/dr-dna

    Special thanks again to:
    bowen
    EvilMonkey
    GnomeTank
    JHunz
    Kakodaimonos

    :)

    Ethereal Illusion on
    camo_sig2.png
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited February 2011
    That is amusing!
    The music is kinda repetive, but that's probably easy to add/change/whatever
    I like the cheevos.

    Monkey Ball Warrior on
    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • Ethereal IllusionEthereal Illusion Registered User regular
    edited February 2011
    That is amusing!
    The music is kinda repetive, but that's probably easy to add/change/whatever
    I like the cheevos.

    Yah we didn't have a sound person on the team so they just threw in some free stuff they found. Which is why I programmed in the mute button. I totally called them cheevos in the code too. Thank you for tryin' it! :D

    Ethereal Illusion on
    camo_sig2.png
  • seabassseabass Doctor MassachusettsRegistered User regular
    edited February 2011
    That is amusing!
    The music is kinda repetive, but that's probably easy to add/change/whatever
    I like the cheevos.

    Yah we didn't have a sound person on the team so they just threw in some free stuff they found. Which is why I programmed in the mute button. I totally called them cheevos in the code too. Thank you for tryin' it! :D

    Just out of curiosity, what did you settle on for path finding?
    My thesis is on traversing implicitly defined graphs, so I'm always curious to see what people in the real world use, even if yours was an explicit graph.

    seabass on
    Run you pigeons, it's Robert Frost!
  • DrunkMcDrunkMc Registered User regular
    edited February 2011
    I need advice on choosing a programming language to study. I have rudimentary knowledge of Assembly and a fair grasp of Java, along with design principles and patterns. I have little difficulty with most programs that can be interacted with from a command line, but I seriously struggle with GUIs and graphics (to the point where I have no idea how most of Java's graphical classes/functions actually work).

    I wish to write a fairly simple grid-based, 2D, turn-based tactical RPG, in the style of X-COM or Final Fantasy Tactics. Which language should I learn and use for that purpose?

    I'm biased towards Java, so you could def. do that in Java using a Canvas object for the grid and sprite placement and writing up all the behvaior with that.

    I am also SUPER biased towards GWT, so if you want to get fancy you can write it in GWT (which uses Java) as a web page. I personally learned most of my Java skills through GWT because it's so easy to get visual feed back based on what code you write. It's not the super best for games, but it can definitely be done. Small Disclaimer though, I recommend GWT for anyone who asks what language they should use. :)

    DrunkMc on
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    So guess what I scored this weekend for $60 total.

    Thanks for going out of business Borders!

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    edited February 2011
    Nice score, bowen. How much was the K&R?

    iTunesIsEvil on
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    MSRP has it at like $55ish on the back of the book, the stroustrup one was like $80.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • The AnonymousThe Anonymous Uh, uh, uhhhhhh... Uh, uh.Registered User regular
    edited February 2011
    ...you lucky bastard. :P

    The Anonymous on
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    Pretty good reference books too!

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • EndEnd Registered User regular
    edited February 2011
    bowen wrote: »
    Thanks for going out of business Borders!

    Oh shit. It looks like they're filing Chapter 11, but they're already planning on closing 200 stores. I should find out if any one of the ones they're closing are near me.

    End on
    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpgsteam~tinythumb.png
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    Yeah so many good books, so little money. I almost picked up some random shit on perl and python too.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • TaminTamin Registered User regular
    edited February 2011
    End wrote: »
    bowen wrote: »
    Thanks for going out of business Borders!

    Oh shit. It looks like they're filing Chapter 11, but they're already planning on closing 200 stores. I should find out if any one of the ones they're closing are near me.

    Let me know if you find a list, eh? I'm looking around for one, but haven't found it yet.

    Tamin on
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • EndEnd Registered User regular
    edited February 2011
    thanks bowen!

    Sadly, my state isn't even in their list at all.

    End on
    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpgsteam~tinythumb.png
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    Yeah mine isn't there, but they're definitely going out of business. I think mine's closing in 2 months which isn't included in that list. IMO, call them and ask if they're one of the stores scheduled for closing soon.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • EndEnd Registered User regular
    edited February 2011
    I'll have to do that.

    End on
    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpgsteam~tinythumb.png
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    Gonna have to read through that ritchie book though, looks pretty good.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Ethereal IllusionEthereal Illusion Registered User regular
    edited February 2011
    seabass wrote: »
    That is amusing!
    The music is kinda repetive, but that's probably easy to add/change/whatever
    I like the cheevos.

    Yah we didn't have a sound person on the team so they just threw in some free stuff they found. Which is why I programmed in the mute button. I totally called them cheevos in the code too. Thank you for tryin' it! :D

    Just out of curiosity, what did you settle on for path finding?
    My thesis is on traversing implicitly defined graphs, so I'm always curious to see what people in the real world use, even if yours was an explicit graph.

    The method wasn't too complicated. I started with a node, then sent out subsequent expanding radial nodes until the target was found, then found the shortest path and used that. Sounds like I used an explicit graph, I think?

    Ethereal Illusion on
    camo_sig2.png
  • PapillonPapillon Registered User regular
    edited February 2011
    ASimPerson wrote: »
    scanf() tends to be a house of cards mainly due to its vulnerabilities more than anything else. Anyway, I don't really see anything wrong here (other than the lack of a default case in your switch statement). I would probably abstract some of those larger switch cases into functions though.

    I gotta say, though, if you actually had to write this out what a huge waste of time. The focus should be on the ALU part. Much easier not worry about interactivity and just let you parse a file or something. Geez.

    I guess I'm a bit late here, but:

    You can write code which uses scanf() securely, you just have to pay attention to the size of your buffers. However, you should never use scanf() by itself. Instead, use fgets() followed by sscanf(). This is because if scanf() fails to parse, the input stream will end up a partially read line and it's difficult to recover (using "cin >> a" has the same problem, btw). Also, if you have several alternatives, you can test against each of them by trying to parse the same line with sscanf() and either checking how many fields have been matched, or checking if the entire line has been parsed with %n.

    In my experience, fgets() + sscanf() is the easiest way of processing input in C or C++.

    Papillon on
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    edited February 2011
    agoaj wrote: »
    Yeah, if I just draw a line between the 2 points it works fine. But if I break it up into steps it curves, which makes tracing that line to do hit detection or moving characters hard.

    Then you have some weird projection issues, are you absolutely sure that the coordinates of the line you're showing is right?

    Try this maybe?

    *displayX = *ratioX * ((Points[0].x - Points[2].x) + (Points[3].x - Points[0].x) * (1-*ratioY));

    If I've understood what you're doing right, the Points are the locations of the trapezoid in space, with 0,2 being the smaller part at the top and 3,1 being the larger base, this determines the width of the trapezoid slice at the y coordinate (top width + change in width * distance from top). I think your problem might be that minX and maxX have weird values at the extremes (if ratioY is 0 then minX is maximum, maxX is zero, if it's 1 then minX is 0 and maxX is maximum), which could cause curving

    Phyphor on
  • bowenbowen How you doin'? Registered User regular
    edited February 2011
    I find examples help:
    #include <stdio.h>
    
    int main()
    {
      char input[75];
      printf("Enter your first name and age:\n");
      fgets(input,75,stdin);
    
      char name[50];
      unsigned int age;
    
      //sscanf should return a nonzero number, indicating a match
      //a good programmer would make sure that the number matches
      //the input we're looking for here
    
      if(!sscanf(input,"&#37;s %u",name,&age)) {
        printf("Well nice to meet you, %s.  I don't know very many %u year olds.",name,age);
      } else {
        printf("Sorry I didn't understand that.");
      }
    
      return 0;
    }
    
    

    Feel free to pick apart my code. :P

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    edited February 2011
    Well, you get to smash the stack due to name being placed after input :P

    Phyphor on
  • seabassseabass Doctor MassachusettsRegistered User regular
    edited February 2011
    seabass wrote: »
    That is amusing!
    The music is kinda repetive, but that's probably easy to add/change/whatever
    I like the cheevos.

    Yah we didn't have a sound person on the team so they just threw in some free stuff they found. Which is why I programmed in the mute button. I totally called them cheevos in the code too. Thank you for tryin' it! :D

    Just out of curiosity, what did you settle on for path finding?
    My thesis is on traversing implicitly defined graphs, so I'm always curious to see what people in the real world use, even if yours was an explicit graph.

    The method wasn't too complicated. I started with a node, then sent out subsequent expanding radial nodes until the target was found, then found the shortest path and used that. Sounds like I used an explicit graph, I think?

    That's a breadth first search.

    seabass on
    Run you pigeons, it's Robert Frost!
  • PapillonPapillon Registered User regular
    edited February 2011
    Phyphor wrote: »
    Well, you get to smash the stack due to name being placed after input :P

    The order of the variables isn't the main problem. The main problem is that he's writing name (which could be up to 75 characters long) into an array which is only 50 characters long. Either increase the size of name, or use sscanf(input, "%50s %u", name, &age).

    You should be checking if the return from sscanf() is equal to the number of fields parsed. I.e. sscanf("%50s %u", name, &age) == 2.

    I also like to add an extra space around my format string so it will gobble leading and trailing whitespace:
    sscanf(input, " %50s %u ", name, &age) == 2.

    Finally, this will still match inputs with extra garbage at the end. You can fail if there's extra garbage by comparing the length of the matched string with the length of the entire string: sscanf(input, " %50s %u %n", name, &age, &len) == 2 && len == strlen(input)

    Papillon on
This discussion has been closed.