Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Urk, I had missed the use of gets() in the original, or I would have mentioned it... using gets() , under any circumstances, is a serious problem, as it doesn't check to make sure that the input will fit into the buffer it reads into. Using gets() is just asking for buffer overruns; in C++, you should use cin.getline() instead.

void getopts()
{
    for (int i = 0; i < 4; i++)
    {
        cin.getline(option[i], 20);
    }
}

BTW, your indentation style is, to be blunt, atrocious. Please be more careful about indentation, or else use an auto-formatter (VC++ 6.0 includes one, IIRC).

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

To begin with, please use [code] tags around all code samples in the future, especially ones as large as this. This is very important, as the code tags force the software to retain the indentation; without them, the code is almost impossible to read.

#include <iostream>
#include <fstream>
#include <math.h>
#include <string>
using namespace std;

float ran1(long *);

#define IA 16807
#define IM 2147483647
#define AM (1.0/IM)
#define IQ 127773
#define IR 2836
#define NTAB 32
#define NDIV (1+(IM-1)/NTAB)
#define EPS 1.2e-7
#define RNMX (1.0-EPS)

float ran1(long *idum)
{
    int j;
    long k;
    static long iy=0;
    static long iv[NTAB];
    float temp;

    if (*idum <= 0 || !iy)
    {
        if (-(*idum) < 1) *idum=1;
        else *idum = -(*idum);
        for (j=NTAB+7; j>=0; j--)
        {
            k=(*idum)/IQ;
            *idum=IA*(*idum-k*IQ)-IR*k;
            if (*idum < 0) *idum += IM;
            if (j < NTAB) iv[j] = *idum;
        }
        iy=iv[0];
    }
    k=(*idum)/IQ;
    *idum=IA*(*idum-k*IQ)-IR*k;
    if (*idum < 0) *idum += IM;
    j=iy/NDIV;
    iy=iv[j];
    iv[j] = *idum;
    if ((temp=AM*iy) > RNMX) return RNMX;
    else return temp;
}
#undef IA
#undef IM
#undef AM
#undef IQ
#undef IR
#undef NTAB
#undef NDIV
#undef EPS
#undef RNMX

//-------------------------------------------------------------------------------------

//--------------------------------------Defining Energy Function--------------------
double annint(double, double);

double annint (double xcoz, double box) //If xcoz is not between (-0.5 to 0.5 * box) it is taken as part of another box
{
    double co1, co2;
    if (xcoz > 0)
    {
        co1 = (int(xcoz/box))*box;
        return (xcoz-co1);
    }

    else if (xcoz < 0)
    {
        co2 = (int(xcoz/box))*box;
        return (xcoz-co2);
    }
    else
        return(0);
}

// The LJ parameters for …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The link which WaltP provided is to a page for precisely that, actually; this link here gives details on different approaches to indent style, with a specific style (Allman) highlighted. A broad search on indent style or brace style should turn up a plethora of information.

If all else fails, you might also look into editing your code with an IDE that has an auto-indent feature. I have lately been using Code::Blocks a lot lately, and that comes with the Astyle tool which I'd used earlier (under Plugins). Visual C++ Express has a good auto-styler as well.

What editor or IDE are you using? Chances are, it already has support for auto-indentation, even if you don't know it.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I have noticed that there are some problems with the indented code posted by Captain Jake, specifically that some braces appear to be missing. I've used AStyle to automatically re-indent the code, which I hope will help make the main bug clearer:

{ 
    int quantityamount1[3];

    for(int i=0; i<3; i++)
    {
        cout<<"Enter quantity for item "<<i+1<<":\n";
        int quantity=0;
        cin>>quantity;
        if(quantity<=wh[0].amt[i] && wh[0].amt[i]>0)  //Searching current warehouse inventory

            wh[0].amt[i]-=quantity;
        quantityamount1[i]=quantity;
    }
    else
    {
        for(int j=1; j<5; j++)
        {
            if(wh[j].amt[i]>0 && quantity<=wh[j].amt[i])  //Searching other warehouses to fulfill order
            {
                cout<<quantity<<" quantity of item "<<i<<" shipped from "<<wh[j].city<<" to "<<wh[i].city<<"\n";
                wh[j].amt[i]-=quantity;
                cout<<wh[j].city<<"  "<<wh[j].amt[0]<<"  "<<wh[j].amt[1]<<"  "<<wh[j].amt[2]<<"\n";
                break;
            }
            else
            {
                cout<<"Order Unfilled\n";//Could not find any warehouses to fulfill order
                quantityamount1[i]=1;
                break;
            }
        }
        quantityamount1[i]=quantity;
    }
}

The problem lies in the else statement inside the inner for() loop; the way it is currently situated, it will end the loop prematurely. You want to take the clause out of the loop and use a separate if() statement to check whether the loop was exhausted without finding the item in any of the warehouses:

for(int j=1; j<5; j++)
        {
            if(wh[j].amt[i]>0 && quantity<=wh[j].amt[i])  //Searching other warehouses to fulfill order
            {
                cout<<quantity<<" quantity of item "<<i<<" shipped from "<<wh[j].city<<" to "<<wh[i].city<<"\n";
                wh[j].amt[i]-=quantity;
                cout<<wh[j].city<<"  "<<wh[j].amt[0]<<"  "<<wh[j].amt[1]<<"  "<<wh[j].amt[2]<<"\n";
                break;
            }
        }

        if (j >= 5)  // for loop was exhausted without finding the sought items
        {
            cout<<"Order Unfilled\n";//Could not find any warehouses to fulfill order
            quantityamount1[i]=1;
            break;
        }

As an aside: you might want to use named integer constants for …

PrimePackster commented: Thanks for pointing out +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

As an aside: you might want to use named integer constant for the number of characters you're reading in, rather than using a magic number the way you are now. It would make reading and changing the program easier, and it is a good habit to get into. For example, instad of what you have now, you could have written:

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<cstdio>
#include<cstring>

using namespace std;

const int LINE_SIZE = 80;

int main()
{
    ifstream inFile ("d:/Text1.txt", ios::in);
    char sentence[LINE_SIZE];

    if(!inFile)
    {
        cerr<<"File Text1.txt could not be opened"<<endl;
        exit(1);
    }

    inFile.getline(sentence, LINE_SIZE);

    cout<<endl;
    cout<<"The file Text1.txt contains the following sentence:";
    cout<<endl;
    cout<<sentence;
    inFile.close();
    cout<<endl;

    cout<<"Please enter a lowercase letter between (a-z):";
    char letter;
    cin>> letter;

    return 0;
}

(Note also the use of the code-tags, which allows the formatting of the code to be retained. You should always post you code with code tags on this forum.)

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Probably the easiest way to convert an integer to a string is by using a stringstream:

int five = 5;

string mystring;
stringstream ss;

ss << five;

ss >> mystring;

A slightly different take on this can be found here; which is better for you depends on what you find convenient.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The problem is that, unless you define them yourself, there are no comparison operators for the Date type. The compiler does not know how to compare one Date value with another.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

can you help?. i know some coding

Certainly I can help, as can several others here. However, writing the code for you would not be Help, it would be Cheating. No one here will help you do that.

We are willing to do quite a bit here, perhaps more than is really called for sometimes; but **you **need to show some initiative first. Post whatever code you have for this (using CODE tags, please), and we can give you advice on it.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You'll need to give us some idea of what you've tried yourself already. No one in this forum is going to do your homework for you.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Ah, that helps quite a bit. The problem is very likely to be in the header files, rather than the using directive itself. It is probably from omitting the semicolon after the declaration of the classes. Can you post Weapon.h and Room.h for us?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I agree with Rohan121212; you need to give more specifics about the program.

The answer to the question would depend on just how the end of the loop is indicated. If you are given a number of cases to enter before the loop begins, then it is fairly straightforward:

int quiz_count; 

    cout << "Number of quizzes to enter: ";
    cin >> quiz_count;
    cin.ignore();
    for (int i = 0; i < quiz_count; i++)
    {
        read_quiz();
    }

OTOH, if you don't have the number of quizzes ahead of time, a while() or do..while() loop would be better:

do 
    {
        read_quiz();

        char another_quiz;
        cout << "Enter another quiz (Y/N)? ";
        cin >> another_quiz;
        cin.ignore();
    } while (toupper(another_quiz) == 'Y');

Do either of these solve your problem?

TaoNinja commented: Helped me out ^_^ +1
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

With all due respect, AD, I think you've misread the code (it happens to the best of us...). There is no class declaration; that's a using namespace directive. Furthermore, even were it a class declaration, there would still be code there which isn't inside of a method.

Ancient Dragon commented: you are correct :) +17
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You're not the first to make this mistake about fflush() ; it sounds reasonable, but the problem is that it doesn't do what you are expecting. In C, the fflush() function only operates on output, forcing it to finish immediately rather than remain in the buffer. Applying it to an input stream has undefined results, and while some implementations do in fact do something, you can't rely on it to work portably.

As for the original problem, the best solution, sadly, is to not scanf() in the first place, but (to give one possible solution) to instead use fgets() to read the input into a string buffer, which you can then apply sscanf() to. This may sound like a strange way to do it, but it would ensure that the input doesn't get blocked up with unwanted characters, and allows more flexibility in how you parse the input.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You're getting closer with this, but in this case, you do not want the double-quotes around the variable names; double quotes are used to demarcate the beginning and end of a string literal. Thus, you should try the following:

cout <<"Encrypted digit:" << digit_three << digit_four << digit_one << digit_two << endl; // display encrypted numbers

As a side note, I should mention that in the future you should always use [code] tags around any code samples you post here. This ensures that the source formatting is retained.

Getting back to the program: at the beginning of the program, you have a variable named main , which you declare as type int and assign the value of zero. I would expect this to conflict with the function name main() , or else get treated as an overload of that name. Either way, having a variable with the same name as a function is almost certain to result in confusion, if not on the part of the compiler then on the part of those reading the code later. I strongly recommend renaming the variable to something other than main .

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Actually, the problem is that you are not enclosing the switch() block in braces, and as a result, only the first case is being seen as in the scope of the switch() statement. This is no different than if you had written an if statement like this:

if (something)
    statement1;
    statement2;
    statement3;

Despite the appearances due to the indentation, only statement1 is actually part of the if() statement. Thus, you actually want it to be like this:

switch (youngrat_choice)
 {
 case 1:
      cout<<"\nYou strike the young rat with your sword\n";
      youngrat_health = ( youngrat_health - attack );
      cout<<"You deal the enemy " << attack << " damage\n";
      
      if ( youngrat_health <= 0 )
      {
           cout<<"You defeated the young rat and earned 5 experience\n points and 12 gold coins\n";
           experience = (experience + 5);
           gold = (gold + 12);
           getch();
           
      } 
      
      else if ( youngrat_health > 0 )
      {
           cout<<"The young rath is still alive!!";
           getch();
           goto startfightyoungrat;   
           
           }
           
      
 case 2:
      cout<<"\nEnemys Stats: \n\nType: Young Rat\nHealth: " << youngrat_health << "/" << youngrat_maxhealth << " ";
      getch();
      goto menuyoungrat;
      
 case 3:          
         cout<<"Name: " << name << " ";
     cout<<"\nLevel: " << level << " ";
     cout<<"\nGold: " << gold << " ";
     cout<<"\nAttack: " << attack << " ";
     cout<<"\nExperience: " << experience << " ";
     cout<<"\nHealth: " << health << "/" << maxhealth << " ";
     
     getch();
     goto menuyoungrat;
     
     
  case 4:
       cout<<"\nYou run away in panic after being attacked\n";
       getch();
       village();   
      
 }
 getch();
  }
  else if ( level …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You don't have any return value for the case where counter does not equal 5, so the caller basically gets whatever junk happens to be in the returned value register - and since any value other than zero (false) evaluates to true, the return value is almost always going to be true.

Actually, I'm surprised that this compiled at all - at the very least it should have given you a warning that not all paths end in a returned value. While C++ is a lot looser than some other languages about this sort of thing - it goes on the assumption that the you know what you're doing - it still should have at least checked to make sure this wasn't an oversight.

Also, in the conditional, the result variable is unnecessary, as is the ' == true ' part, and the winner assignment as well; you could simplify the whole thing as just:

if((checkFlush(checkCards)))
    {
        return 5;
    }
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The main issue I see with this is that you don't have break statements at the end of the cases. This means that the first case will 'fall through' to the second, which results in the fee always being set to 20.

Nastadon commented: Thanks bro +1
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

add return type for BasicLCG(); and BasicLCG(unsigned long); It should solve you first 4 compilation error

Yes, but it does nothing for the redeclaration error immediately below it. C doesn't allow function overloading; you'll need to give the two different functions different names. Furthermore, those two functions are constructors in the original; there's no fixed equivalent of that in C.

hairo: If you don't mind me asking, why are you converting C++ code to C in the first place? Unlike going in the other direction, there are substantial problems in doing this, and probably little to be gained. What is this for? You might be better off writing the C version from scratch, just using the random number algorithm but writing new code.

Ancient Dragon commented: agree +17
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Unfortunately, if you're writing the boot sector yourself, then you'll need to have some way of loading the OS image file, which means writing at least a minimal version of the loader and enough of the file system to find the file in question. The usual solution is a two-stage boot loader, with the second stage being an assembly program which is loaded from a fixed position on the partition and contains enough of the file system and loader to get the actual boot image loaded. If you are using a 32-bit C++ compiler, you'd also need the code that sets up the GDT and switches to protected mode before jumping to the C++ code, as well.

Rather than rolling your own boot loader, you might consider using an existing multi-boot loader such as GRUB. I know that you had said you didn't want to deal with Linux, but GRUB is not for Linux alone: it should be able to load any conventional operating system, assuming that the image file was compiled to ELF format, or you can use chain-booting to load something in a different format (though in that case you'd still need to be able to load the file itself from scratch). Since it does a lot of the heavy lifting with regards to the memory setup and protected mode state, you'd save a great deal of effort in doing things this way.

I would recommend that you look into the information available at

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I'm not sure why it would give that specific error message; it is more typical of certain types of header problems. You might try using 'g++' rather than 'gcc'; by default, gcc assumes that you're compiling a C program, while g++ is specific to C++.

I would also recommend always using the '-Wall' switch with gcc and g++, like so:

g++ -Wall testing.cpp -o test

This option turns on all of the warnings which the compiler can give you - by default, most of the diagnostic warnings are turned off, but having them turned on is very helpful in debugging.

As for the second shell command, the reason it can't find the file is because you aren't in the directory the file is in, and you haven't told it which directory to look for it. By default, when you open a terminal in Linux, it starts off in your home directory, '/home/john/' in this instance. If the source file is in a folder on your Desktop, you need to either give it the path to the file, or else change directories so that you are in the same folder as the file. In this case, the latter can be done with the simple command cd Desktop/C++ , which should change your current working directory to '/home/john/Desktop/C++/'. If you get confused as to where you are, you can use the command pwd to get your working directory.

BTW, the tilde ('~') in the path of …

anirudh33 commented: informative and its solved :) +2
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You can find extensive information, including sample boot loaders, at OSDev.org. I would recommend being careful about posting to the fora there, however, as they expect you to carry your own weight, and a blanket request such as this one is likely to get negative reactions.

That having been said, I would recommend using GRUB as your bootloader rather than trying to roll your own. GRUB does many of the basic startup tasks for you, and let's you start from a fairly well-developed point.

As for a command-line action, you're on your own.

Zssffssz commented: He seems like the only person that helps people with asembly, he gets there fast and helps you find your answer! +1
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I think that the problem lies with the getmodelno() function itself, and what you are expecting it to do. As it is written right now, it prints the model number to the screen, but does not return it's value. If you want the function to act as an accessor (also called a getter), then you'd have to write it as:

char* getmodelno()
{
    return lmodelno;
}

You might want to use the string class instead of C-strings, however, as they are much easier to work with.

On an unrelated note: while void main() is accepted by some compilers, strictly speaking the correct usage is int main() according to the standard. While the standard allows compilers to accept void main() for those cases where there is no OS to return to, it is considered a non-portable extension.

I was also curious as to why you were using such an outdated compiler. VC++ 6.0 is from 1998, and there are several more modern compilers available for free, including the newest version of Visual C++ Express. Are you required to use the older version for class? I know several schools use older compilers as a matter of standards (Turbo C++ being the most notorious), but it is in my arrogant opinion a poor practice.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I am certain that someone here can, if you show us what you've already done first. Doing the work for you, however, would not be considered 'helping' by most of the folk here.

(I've actually been criticized for posting too much 'help' at times, rather than giving the original poster the chance to work out a problem themselves, and I deserved it, too.)

I should add that Prolog is a family of incompatible dialects, rather than a single language. It would help if you told us which interpreter or compiler you are using.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Hold on for a moment, though; just how are you adding the list to the SQL statement, and how are you vetting the data, if at all? Generally speaking, any data added to a SQL query programatically should be done using a parameterized query:

cursor.executemany("INSERT INTO table values ('?', '?', \"?\", '?');", 'querty', 'uiop', "[u'ás', u'és']", 'a')

The way you describe it, it sounds like you were concatenating the strings together directly, which (unless the data is checked out ahead of time) could leave you open to a SQL injection attack.

griswolf commented: Very good point +11
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

the if statements are incorrect; in Java, you cannot compare a range the way you are trying to do. This is a common misunderstanding, as it makes sense mathematically, but doesn't work in most programming languages.

You need to write out a full clause on each side of the or operator:

import java.io.*;
public class Konata {
    public static void main(String args []) {
        BufferedReader br=newInputStreamReader(System.in);
        int grade,answer=0;

        do {
            System.out.print ("\n Enter grade");
            grade=Integer.parseInt(br.readline());

            if ((grade>=90)||(grade<=100)) {
                System.out.print("\n A");
            }
            else if ((grade>=80)||(grade<=89)) {
                System.out.print("\n B");
            }
            else if ((grade>=70)||(grade<=79)) {
                System.out.print("\n C");
            }
            else if ((grade>=0)||(grade<=69)) {
                System.out.print("\n F");
            }
            else { 
                System.out.print("\n out of range");
            }

            System.out.print("\n Do you want to try again? Press 1 for Yes and Press 0 for No:");
            answer=Integer.parseInt(br.readLine());
        }while (answer==1);
    }
}

Note that I reformatted the code according to the Java standard. You should generally follow this standard, as it makes the code more familiar and more readable.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Could you start by showing us what you've already done?

The heart of this problem is writing a sorting function; however, since there is a small, fixed number of items to compare, it might be easier to do it ad hoc than to write a full function. You could simply do something like this:

set up an integer array of size three
read in the first two numbers
compare the numbers, and put the larger in the array slot 2
put the smaller in the array slot 0
read in the third number
if the third number is smaller than the array[0]
    copy array[0] into array[1]
    copy the third number into array[0]
else if the third number is larger than array[2]
    copy array[2] into array[1]
    copy the third number into array[2]
else
    copy the third number into array[1]

print out the results
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

It isn't hard to see where the problem lies, now that we've seen the code. What's going on is that you declare the variables and define several functions in the header itself; this becomes a problem when you then #include said header in more than one compilation unit. To get the desired result, you need to have the functions and variables in the constants.cpp file, and only have function prototypes and extern declarations in the header. So, for constants.h you would have:

#pragma once
#ifndef CONSTANTS_H
#define CONSTANTS_H

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_ttf.h"
#include <string>

//constants
extern const short SCREEN_WIDTH = 640;
extern const short SCREEN_HEIGHT = 480;
extern const short SCREEN_BPP = 32;

extern const short TILE_SIZE = 32;
extern const short NUM_OF_TILES_X = 20;
extern const short NUM_OF_TILES_Y = 15;

extern const short GAME_TIME_IN_SECONDS = 60;

//globals
extern SDL_Surface* screen = 0;
extern SDL_Event event;
extern SDL_Color textColor = { 255, 255, 255 };

SDL_Surface *load_image( std::string filename);
void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination);
bool SDL_Initialization(std::string caption);

#endif

You would basically then put the definitions in constants.cpp instead.

You need to understand how the #include directive works, and how it interacts with the linker. When the preprocessor reads the #include directive (before the compiler itself is run), it immediately replaces the directive with the entire contents of the file being included, then runs through and performs the normal pre-processing as if nothing had been done. So, if you have a file foo.h …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Well, aside from the fact that you don't declare the eight variables you use to get the bit values, it should work - if that's what you need it to do.

However, assignments like these more often involve converting a binary number in a string, which works a bit differently. Fortunately, there is a fairly easy algorithm for converting strings of any base to a standard integer, and vis versa. The general algorithms (in Python, though they should be understandable well enough if you treat it as pseudo-code) can be found here; you'll want to use the second algorithm, the one titled 'str2int()'.

sergent commented: Helpful +4
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

There shouldn't be any size limitations on ftplib.storbinary(), no. However, the fact that the error message is coming from the server you are uploading to, rather than the local client, implies that the problem is occurring on the server end.

Looking up the list of FTP error messages, you'll see that the standard error 500 is a syntax error, usually from a command that is too long. The error message you're getting, however, sounds more like a 553 error - 'filename not allowed'. It may be that the server has limits as to the types of files it permits you to upload, but that is speculation. Could you post the traceback from the error, and the relevant code?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

There aren't really any Python certifications at this time, at least not ones which anyone would have any reason to pay attention to; Brainbench has one, as does ExpertRatings, but I doubt that any company would really make hiring decisions based on them (while some companies do ask you to take those tests, they don't appear to require them). The only one which could be considered in any way 'official' would be the one from O'Reilly and Associates, which hasn't been released yet (it is slated to be out next month). Even that is more a certification that you took their coursework (at considerable expense), rather than a demonstration of proficiency.

As for writing a certification exam, as opposed to taking an existing exam, well, you're on your own with that.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Valid point; I misspoke myself. Thank you for the correction.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

To answer the last question first, the solution is simply to add #include <time.h> at the top of the code file. This automatically copies the structure definition into your code, without setting off alarm bells with the compiler.

Oh, and itoa() is deprecated, and is not part of the standard library; a better solution is to use

sprintf(time1, "%d", tm_min);

As for the original question, well, as I said earlier, chances are a linked list would be what you want. You would re-define the struct as

struct jatekos
{
	char nev[20];
	int dob1;
	int dob2;
	int dob3;
        struct jatekos* next;  
        /* You might use 'kov', perhaps? I don't know Hungarian, I just checked Google Translate for an equivalent and it gave 'következő' */
};

jatekos* head;

You would need to define functions for adding, removing, searching, etc., but those aren't too difficult to write.

The other alternative is to use an extensible array, which Ancient Dragon already explained the basics of.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

And i really don't think that THIS IS THE FRIENDLIEST IT Community. Starting off with your RUDE REPLY

Trust me, had you posted to, say, DevShed with the attitude you've displayed, you would have seen what a rude reply looks like. You should thank us for our grandmotherly kindness in setting you back on the path to good coding.

That having been said, I should say that you might be able to redeem yourself in the eyes of the forum by posting the code you've already written (properly, using [CODE tags) and asking specific questions about the problems you are facing with it. While we may seem rude, we do want to help you solve the problem; however, there is a world of difference between 'helping you program better' and 'helping you get a passing grade'. We want to do the former, if for no better reason than that we may have to work with you someday, while the latter is of little real consequence to us no matter how important it may be to you.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Actually, there is a project to write a 32-bit version of FreeDOS, called (naturally enough) FreeDOS-32. I don't know if it is an active project or not, but you might consider contributing to it if you are genuinely interested in it.

However, as Ancient Dragon said, DOS is pretty much a dead topic, even where OS development is concerned.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I'm not sure why you're having trouble passing strings, but it certainly ought to work. For example:

def printString(my_str):
    print(my_str)

I suspect where you're having trouble is in passing values to methods, but that too should be straightforward; you simply put the arguments after the self argument.

class Player():
    def __init__(self, inithealth = 10):
        self.inv = []
        self.health = inithealth
        
    def hurt(self, damage):
        print "Hurting player for {0} damage.".format(damage)
        self.health -= damage
        
    def use(self, item):
        if type(item) is not str:
            raise TypeError
        elif self.inv.count(item) < 1:
            print 'There is no {0} in your inventory.'.format(str(item))
        else:
            item.use()
            self.inv.remove(item)
            
    def print_inv(self):
        for slot, count in enumerate(inv):
            print count, + '. ' + str(slot)


if __name__ == '__main__':
    player = Player()
    player.hurt(2)
    print r"Player's health is now at", player.health
    player.use('apple')

(BTW, it is a convention in Python to capitalize the first letter in the name of a class. While you don't have to follow this convention, it will probably save you trouble and confusion if you do. For more on Python typographical rules, see PEP 8.)

TrustyTony commented: Nice work! +13
vegaseat commented: good help +15
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Could you explain a little more about what you're trying to do? There may be some other ways to solve this problem.

If what you need is the input string, and not the error message, then this should work:

inString = input()
try:
    x=int(inString)
except ValueError as var:
    print(inString)
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The single vertical bar is for the bitwise OR operator. What the code is doing is taking the S_IFDIR flag (which indicates if a given file handle is actually for a directory), and overlaying the bitfield for the desired file permissions, which results in the overall file mode value. See here and here for more details.

BLUEC0RE commented: Very informative post +2
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

WolfShield: You've omitted some crucial details here, starting with, what GUI library you're using (I'd normally assume TkInter, since that's bundled with Python, but this doesn't seem like Python/Tk code). While it is not exactly relevant to the code section in question, it does make it harder to judge where the error is occurring.

Tonyjv: If you look, WS is in fact passing the values as parameters when calling calculate() in the equPressedF() event handler. The problem is, the function doesn't seem to be using the passed values, for some reason.

Or perhaps not... I suspect that the error is coming up in equPressedF() rather than in calculate() . WolfShield, could you please post the traceback that you get when you omit the globals?

Where are the values being passed to equPressedF() meant to be coming from? I am guessing that you intend for them to be read from a pair of textboxes, correct? so where are you reading the values in those?

You might want to decompose the code a bit more, separating the implementation of the calculate() function from the GUI code. This should make testing the parts easier. I tried the following successfully:

def calculate(num1, num2, oper):
    """ Function to act as a simple six-function calculator.
    
    arguments:
        num1 -- first argument of the operation
        num2 -- second argument of the operation
        oper -- string representing the operation to perform
    """
    print("calculate() called")
    if(oper=="+"):
        answ = num1 + num2
        return answ
    elif(oper=="-"):
        pass …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

While Gribouillis's answer is correct, it could probably use more explanation, because the dot-member notation is used somewhat differently in C++ than in Python and it may be somewhat confusing.

In C++, variables have an explicit type, unlike in Python, where variables are typeless (type being a property of the objects which variables reference, not the variables which reference them). There are many different types in C++, but for our purposes there are two broad categories that matter: value variables and pointer variables.

All local named variables in C++ are stored on the stack, a system data structure which keeps track of function calls. When a function in C++ is called, all the information needed for that function - both where it needs to return to, and what variables and arguments it has - is pushed onto the stack, and access to the variables is done by offsets into the stack area. Most of the time, you have variables whose values are the actual data you are working with - for example, if you have an integer value, the integer is stored in the very location on the stack which the variable name refers to. You usually don't need to know all of this - the compiler does this part for you - but it is important to understand that the amount of local memory you have for the function is fixed when the function call is made, and that the local values only exist during the lifetime …

TrustyTony commented: You put your heart in it +13
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The try blocks are not necessary in the first place. Printing "the hourly rate is not a number" is worse than letting an exception propagate, because the exception gives you the line number where the error occurred and the functions which where called, etc.

Ordinarily I would agree, but in this case, the error would almost always be in the data file, not the code. Therefore, it makes sense to indicate where in the data the problem occurred, and then attempt to continue processing the rest of the data.

TrustyTony commented: Good point of warning about specific bad data and going on +2
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

It depends on how you're handling the inserts, and whether you're using the list as a queues or not. If you are inserting to the end of the list, then having a pointer to the last element is a practical way of speeding up insertions. However, how you insert may depend on how you are using the list.

If you are using the list as a first-in-first-out queue, then it makes sense to have an end pointer, as you would need rapid access to both ends of the list, and would want to insert to the end.

However, if you're using the list as a stack, it would make more sense to insert to and remove from the top of the list, in which case having an end pointer isn't helpful.

If it is an ordered list, you can use the end pointer to see if an inserted element sorts higher than the current end of the list, in which case you can insert to the end directly; otherwise, you would have to traverse the list to find the insertion point. Whether this optimization is worth the trouble would depend on whether you expect most new elements to come at the end of the list or not.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Actually, the align type doesn't impact the maximum size of the segment. In real mode, a segment has a maximum size of 64K, regardless of any other factors, and segments are always aligned on 16-byte pages. In other memory modes, things get more complex, and you can have segments of up to 4Gb in size.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

we can start by 'correcting' the indentation, courtesy of astyle:

#include<stdio.h>

int main()
{
    int i, j;
    int n,M[10][10],min=3267;

    /* read in the values of the matrix */
    printf("\nEnter the order of square matrix:");
    scanf("%d",&n);

    for(i=1; i<=n; i++)
    {
        printf("\nEnter the elements of the row %d:",i);
        for(j=1; j<=n; j++)
        {
            scanf("%d",&M[i][j]);
        }
    }

    /* print out the matrix as confirmation */
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            printf("\t %d",M[i][j]);
        }
        printf("\n");
    }

    printf("\nNow subtract each element from every row from their respective minimum  value\n");

    /* find the minimum value for each row and subtract it from the row elements */
    for(i=1; i<=n; i++)
    {
        min = M[i][0];      /* reset the minimum value to the first element of the row */
        for(j=1; j<=n; j++)
        {
            if(M[i][j]<min)
                min=M[i][j];
        }
        for(j=1; j<=n; j++)
            M[i][j]=M[i][j]-min;
    }

    /* print the resulting matrix */
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            printf("\t %d",M[i][j]);
        }
        printf("\n");
    }
}

And I have to concur about the SMS crap - if you persist in it, I doubt anyone will bother reading your posts, never mind answering them.

Finally, I think you'll find that Adak was right: I added the line

min = M[i][0];      /* reset the minimum value to the first element of the row */

and the program now runs correctly. HTH.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Basically, the function returns the difference between the lower number and the higher number, if and only if the lower number is the first number. The 2 is to account for the fact that both the lower number is being incremented and the higher decremented when they are passed to the recursive call.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I'll do the OP a favor here and repost his code (retrieved via Reply) with appropriate formatting:

import urllib
import zipfile
import re

totaal = 0
commentaar = []
lus = True
image = urllib.URLopener()
image.retrieve("http://www.pythonchallenge.com/pc/def/channel.zip","channel.zip" )
bestand = "readme.txt"
zf = zipfile.ZipFile('channel.zip')

while lus == True :

    for filename in [ bestand ]:

        try:
            data = zf.read(filename)

        except KeyError:
                print 'ERROR: Did not find %s in zip file' % filename
        else:
                print filename, ':'
                data = repr(data)
                print data
                comments = zf.infolist()

                for test in comments:
                    commentaar.append(test.comment)
                print

        nummer = re.search('\d{2,}', data)

        try:
            bestand = str(nummer.group())+".txt"
            print bestand

        except:
            lus = False 

print commentaar
vegaseat commented: thanks +13
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

If OS development is what you have in mind, you might want to look into the OS-Dev Wiki and forums. I'll warn you, though, they are not very tolerant of those who come into their message board unprepared, or who don't follow the forum rules; make sure that you've exhausted your other resources before posting a question there.

Ancient Dragon commented: Excellent :) +33
sree_ec commented: Excellent URL :) +1
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Answering the first question second, I would say that it depends, but generally speaking, you would want to keep the serial device open rather than repeatedly opening and closing it. Opening and closing may not have that high an overhead, but they do have some, just as with opening and closing files.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The problem lies in the while() loop in inventoryValue(); the index variable, i, is never getting incremented, so it loops indefinitely on the zeroth element of the array. I would recommend changing it to a for() loop to make the intent clearer, in any case:

int inventoryValue(carType cars[], int currentCarCounter)
{
    int sum=0;
    for(int i = 0; i<currentCarCounter; i++)
    {
        sum+=cars[i].cost*cars[i].numberOnHand;
    }
    return sum;
}