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

N1GHTS: Having been there myself, I'd say that it is mostly because, to most beginning programmers, it looks like the biggest possible challenge to their skills, and the biggest ego boost around. It is also, for a handful of developers, seen as a chance to contribute something fundamental to the field itself - if they think they have some new idea that could change how things are done (they probably don't, but they may think they do). Third, many would-be OS developers start off with only a fuzzy idea of what constitutes an operating system, a kernel, a shell, a user application, and so on; and confuse things like the GUI or the shell with the OS proper, giving them a distorted idea of what OS development takes. Finally, quite a few would-be OS developers dream of supplanting Windows with their own special OS, and imagine the accolades (and money) that would come of it.

It is a worthwhile project, and you learn quite a lot about programming in doing it, but the odds are it won't ever reach the summit you imagine it will. As for the time taken on it, you have to remember that most OS developers are hobbyists, and that the actual time spent on it is only a couple of hours a week in most cases.

The irony is that OS development is not the holy grail of programming the way many see it to be (as I say, I've been there myself, …

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

Interesting. There have been more answers to this question since the OP announced that he was deleting his account than before he did. Given that the OP is almost certainly not reading this, it seems rather quixotic to be answering this now.

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

A lot of these questions can be answered at http://wiki.osdev.org, where there are extensive FAQ lists and other beginner's information that would help you understand what you are undertaking. There is even a specific page on common beginner's mistakes, which addresses the last question directly.

How do you make a kernel? Oh, how to begin... You first need to understand what a kernel is, and more importantly, what it is not. The kernel is, in effect, a program which contains the minimal operations of the system. It is responsible for managing memory; handling interrupts (a type of simple message sent by the hardware, indicating when something has occurred); starting, managing and stopping processes; and providing a mechanism for communication between processes (semaphores, messages, etc.).

That's about it.

Now, some things may be part of the kernel, but aren't necessarily, may include some common device drivers (e.g., basic disk I/O); a minimal file system (for finding the files that the kernel needs); and some ability to report error messages.

Things that are often part of or done by the operating system, but not usually inside the kernel proper, are the user file system; general-purpose I/O; loading of executable files to run as a process; loadable device drivers; higher-level IPC functions such as sockets and pipes; basic networking; and system configuration.

Things that are not part of the kernel, and usually aren't even part of the OS itself, include the graphical …

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

The OSDev website may prove to be particularly useful. When I was working on similar plans (now long since derailed by the various intrusions of harsh reality, but my life isn't necessarily yours), they were vastly helpful, and I in turn contributed to their knowledge base as I could.

You will want to tread lightly in the forums, however, as they do not suffer fools gladly - and generally assume any newcomer is a fool until they have proven their worth. I strongly advise lurking for some while and reading through the archives before posting there.

I will repeat a piece of advice given in the link Griswolf gave: C++ is not a very suitable language for kernel development, at least not without a lot of support work. Several language constructs (e.g., templates, the memory management operators) require quite a bit of runtime support from the OS, and would have to be avoided - leaving you with what is essentially C with a few add-ons. The same is true of most other popular languages, as well. While C is far from the only option, most of the other language choices - including C++ - add substantially to the initial effort and the amount of assembly programming required. If you do decided to use C++, this page will fill you in on the extra things you'll need to know.

(Of course, I am hardly one to talk about …

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

Hmmn, the results were quite different from what I'd expected, for the first line in particular (I suspect my old Lisp biases are showing through on that one). I may need to go back to review certain aspects of the language.

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

While I am ordinarily very much in the 'high level first' camp, I have to admit that today's Daily WTF gives a strong argument in favor of making sure new programmers get a strong grasp of low-level techniques.

Then again, the Daily WTF taken as a whole is a strong argument in favor of shotgun mouthwash (especially the notorious 'Tossing Your Cookies' article), so I suppose that taking it too seriously will only be excessively depressing.

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

Perhaps it would be a good time to point out that the OP never said anything about allocating the memory for strings, specifically. We have no way to know, from the given information, what the allocated memory is being used for, hence the questions about purpose.

Given that the OP has not replied to any of the follow-up messages, however, it is very possible that this entire discussion is moot.

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

That looks like what I would expect from java.util.Date , NormR1. Good work testing that, however, as it demonstrates that the OP isn't using the standard Date class.

I did some checking, and the SQL Date class ought to print the date in YYYY-MM-DD format by default. I'm wondering just what Date class the OP is using. Again, if you could post the import list, it would be very helpful for us in figuring this out.

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

Using a DateFormat is not a workaround; is the intended solution when formatting the standard Java Date object to a String . Mind you there are two very different Date classes in the standard Java library: java.util.Date , which is used to hold a generic date and time (as a millisecond counter from 1 Jan 1970 00:00.00, the same as a Unix time_t ), and java.sql.Date , which holds a SQL date value and cannot be used as a general date value. My guess is that you've imported the SQL Date by mistake (something which is easy to do in Eclipse, given how the auto-import tool works), as the utility Date class does in fact have a usable (if not very useful) toString() method. You should be able to tell by looking at the list of imports at the top of your source file.

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

The issue is that you aren't getting a string value from your Date object; as a result, it is printing the class and hash for today , rather than an useful information. At minimum, you need to use today.toString() , which would give the time and date in UTC format; better would be to use a SimpleDateFormat object to format the date in the manner you need it to appear in.

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

I was assuming that the sorting was part of the assignment, i.e., something that had to be done manually.

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

Oops. I was so caught up in fixing the syntactic problem that I completely ignored the logical flaws.

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

What are you allocating the memory for, and why do you need to ensure that it is cleared/populated?

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

Do you happen to know why they want things in DOS?

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

The first thing you need to know about assembly language is that it is specific both the the type of computer you are using, and to the operating system it is running. Furthermore, each assembler (the programs that convert assembly language programs into object code) has it's own variant syntax, and programs written for one assembler generally won't assemble using a different one.

If you are looking to write programs for Windows systems, and don't know what assembler you have or don't already have an assembler to use, then I would recommend following Sergent's advice. NASM is about the easiest PC assembler available, and several editors such as Notepad++ or SciTE have compatible assembly language modes for it.

If you are looking just to find out what assembly programming is like, and don't mind using a simulator, then you may find that SPIM is an easier solution; it simulates a MIPS processor, which is a type different from the one used by Windows machines, but is much easier to learn with. The simulator provides a good deal of additional support for debugging programs, and shows you exactly what is going on 'under the hood' as the program is running. The MIPS assembly language is vastly simpler than the x86 assembly, as well. The only hitch is, you don't get to see how a program would run on a real system, just on the simulator. Still, you could probably learn MIPS assembly language, …

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

As the problem instructions say, you need to have the second loop nested inside the first loop. in this case, all you really need do is remove the two cout lines between the loops, and move the endl off of the the inner loop's output, and you should be good to go:

for(i=0; i<row; i++)
    {
        for(i=0; i<width; i++)
        {
            cout << "O";
        }
        cout << endl;
    }

You may need to modify this slightly if you need to make a box rather than a filled rectangle.

Note that it is almost always best to explicitly brace any blocks, even when there is only one following statement inside the block. The only real exception to this that I can think of is when using the if/else if/else idiom.

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

I think I've solved the problem; you need to add an additional space for the zero delimiter each time you malloc() or realloc(), as the sizes you are using do not take the extra character into account.

Mind you, there is still some leaking memory, and at one point malloc() is being invoked with an argument of -4 (not sure how that happened). Here are the altered functions:

char *strndup (const char *s, size_t n)
{
  char *result;
  size_t len = strlen (s);

  if (n < len)
    len = n;

  result = (char *) malloc (len + 1);
  if (!result)
    return 0;

  result[len] = '\0';
  return (char *) memcpy (result, s, len);
}


StringBuffer *strbuf_new(const char *cstr){
	StringBuffer *strbuf = (StringBuffer*) malloc(sizeof(StringBuffer));
	if(strbuf == NULL){
		return NULL;
	}
	else{
		if(cstr != NULL){
			char *string = (char*) malloc(sizeof(char) * (strlen(cstr) + 1));
			if(string == NULL){
				return NULL;
			}
			else{
				strcpy(string,cstr);
				strbuf->contents = string;
				strbuf->length = strlen(string);
			}
		}
		else{
			char *NULLString = (char*) malloc(1);
			if(NULLString == NULL){
				return NULL;
			}
			else{
				strbuf->contents = NULLString;
				strcpy(strbuf->contents,"");
				strbuf->length = strlen(strbuf->contents);
			}
		}
	}
	return strbuf;
}


StringBuffer *strbuf_append(StringBuffer *buf, const char *cstr){
	if(buf == NULL){
		return NULL;
	}
	if(cstr == NULL){
		return buf;
	}
	else{
		char *newString = (char*) realloc(buf->contents, buf->length + strlen(cstr) + 1);
		if (newString == NULL){
			return NULL;
		}
		else {
		    if (buf->contents != newString) {   // in the case where the buffer got moved
                free(buf->contents);
                buf->contents = newString;
		    }
			strcat(buf->contents, cstr);
			buf->length = strlen(buf->contents);
		}
	}
	return …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I just tested the program as given above, using Code::Blocks 10.05 for Windows/GCC 4.4.1, and it compiled and ran smoothly. Oddly enough, it was in Linux that I had trouble - the "ansidecl.h" header file wasn't recognized, and the manual declarations of malloc() and memcpy() also presented problems, though once I removed those it once again ran fine.

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

Making my functions inline did the trick!

I think you're taking away the wrong lesson, here. While making the functions inline will work, it isn't the best practice, as inlining larger functions is very inefficient in terms of space - especially if you are calling them in several places. The real solution, in the long term, is to put only function prototypes in the header, and place the functions themselves in a separate file:

functions.h

#ifndef FUNCTIONS_H
#define FUNCTIONS_H

//function prototypes
extern float sum(vector<float> &v);

#endif

functions.cpp

#include "functions.h"

//calculate sum of a vector
float sum(vector<float> &v)
{
int num=v.size();
 float sum=0.;
 for(int ss=0;ss<num;ss++)
   {
     sum+=v[ss];
   }
 return sum;
}

The separate file will need to be compiled separately and linked into the main program, though with most modern IDEs this is done automagically by the project feature.

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

Thank you for pointing those errors out, Tonyjv; you are completely correct, and I had overlooked them this whole time.

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

Still date i dont have an any source code or algorithm for extract the text if any

Correct me if I am wrong, but the purpose of a thesis paper, in most cases, is to present a novel solution to a problem such as this. Unless your paper is a survey of existing techniques - and I doubt that any thesis advisor would recommend that approach in this field, as it would be obsolete by the time it was reviewed, never mind published - there isn't going to be any off-the-shelf code for your solution, for the simple reason that it didn't exist before.

I am assuming here that "Text Extraction from Heterogeneous Images using Mathematical Morphology" is the general topic of the paper, not the title, and that your paper is meant to add to the work done in the existing paper of that title. Would your thesis advisor would be this Dr. Srikrishna, by any chance? Even without knowing anything about her but her title and name, I doubt that she would assign this subject to you unless she expected you to contribute something new to the existing body of work - and it is a good guess that a department head certainly wouldn't expect a student to plagiarize from her own work so boldly as to steal the very title of one of her own papers.

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

Given that this is a disassembly from VC++ 2010 (as noted by the reference to MSVCP100.DLL), you would expect the disassembler to be using Intel syntax, meaning that MOV operations are dest, src rather than src, dest. Thus, some of your comments are probably backwards with regards to what values are being stored in which registers. Specifically, you reverse the order in at least two cases towards the bottom.

Keep in mind that std::cout is a an ostream object, not a function. thus, when it is pushed onto the stack, it is as an argument to the operator<< function, not as a function pointer.

Also, I think (though I may be mistaken) that stream manipulators such as std::endl are passed to the stream operators as arguments, to be invoked by the stream function as the need arises. This would explain why std::endl is pushed onto the stack twice at the beginning of the function call. You might want to rad up on how manipulators work for further details.

MOV EAX,DWORD PTR DS:[<&MSVCP100.std::endl>]               ; deref the std::endl function ptr from the DLL
MOV EDX,DWORD PTR DS:[<&MSVCP100.std::cout>]               ; deref the std::cout object from the DLL
PUSH EAX                                                   ; /Arg4 = function ptr to std::endl 
MOV ECX,EAX                                                ; copy the ptr to std::endl to ECX (not sure why it does this,
                                                           ; probably an artifact of the compilation process that should have
                                                           ; been optimized out
PUSH ECX                                                   ; /Arg3 = function ptr to std::endl
PUSH Reversin.012E3214                                     ; /Arg2 …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The problem is that you are changing the meaning of p before you test p->value, which means that you don't know yet if p (and hence p->value) is valid. You want to test q->next, not p->next:

while((p!=NULL))
	{
	q=p;
        p = p->next;
		if(q->value = a)
		{	
			printf("correct value\n");
			p=q->next;
			q->next = p->next;	
			print_list();
			free(p);
			free(q);
		}
		else
		{
			printf("value of p is wrong");
		}
	}

PS: You're indent style is unusual; is that by intention?

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

Could you tell us something about the problem, e.g., what error messages you're getting, how it is misbehaving, and so on?

I can tell you a few of the problems I see off the top of my head. First off, the initializers for array and ZeroCounter are incorrect; also, you defined the index of ZeroCounter as 'x', which won't work the way you expect - the value of an array index has to be a compile-time constant. Here are two declarations which ought to work:

int array[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
    int ZeroCounter[3] = {0, 0, 0};

Also, there is no standard function named randomize() in C. What you need to do is first call srand() with some suitably unpredictable seed value (the current time should be sufficient for this case), then call rand() to get the actual random numbers.

Here is a quickly modified version of your code, with the changes I suggested; I hope you don't mind that I re-formatted the code according to a more typical indent style, but I think most people here will be able to follow it more easily than your more idiosyncratic style.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()

{
    int array[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
    int sumRow[3], sumCol[3];
    int x=0, y=0;
    int RandRow=5, RandCol=5;
    int cntr=0;
    int diffRow[3] = {0}/*, diffCol[3]={0}*/;
    int ZeroCounter[3]= {0, 0, 0};

    srand(time(NULL));

    for(y=0; y<2; y++)
    {
        if(y==0)
            for(x=0; x<3; …
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

What Narue said is pretty much on the money, but the way the answers are given may be a bit confusing. Allow me to re-post an old piece I wrote on DevShed many moons ago:

http://forums.devshed.com/showpost.php?p=2001351&postcount=14

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

AFAIK, there is no portable way to get the size of a file, because the standard library doesn't really have an abstraction for files per se (despite the standard FILE handle). Rather, it is all based on streams, which in principle can be of indefinite length. Files (as opposed to streams) are a system-dependent concept.

Also, I think we're overlooking something important. From my reading of the problem statement, the OP doesn't want a single array with all of the characters; instead, the problem statement calls for an array of words, or to be a bit more concrete, a pointer to a pointer to char ( char** ). The size of the array presents a problem, as even if you know how long the file is, it tells you nothing about the number of 'words' in it, except that it will be equal to or less than the file size. It also tells you nothing about the size of the individual words.

In other words, this is a tokenizing problem.

My recommendation is that, rather than an array of c-strings, you would be better off with a linked list, with each node holding a single char* for the given word. You would still need to read the file into a buffer, but it need not hold the entire file in memory at once; rather, you could buffer part of the file, then process that section to get the words in it (you've have to handle the edge …

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

actually, I suspect that what he's really looking for with the first question is not to be able to add members to the struct, but to be able to dynamically allocate new structs which would be associated with some other data structure, such as a linked list or a tree.

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

I realize that this is what the error message is asserting, but if you look at my code, you'd see that the parameter in question is in fact being added to the SqlCommand.

I don't see how using an array would make the code any clearer, as it actually loses some information about the parameters (the name of the SqlParameter, which relates it to the parameter it represents). Could you elucidate further on why that would be a better approach?

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

As an aside, the textbook Assembly Language Step by Step has an excellent explanation of the hardware stack. The book focuses on programming for Linux, but with a virtualizer such as VirtualPC or VirtualBox, it is easy enough to set up a virtual Linux system running inside a Windows PC.

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

Ah, no, I did not; I wasn't aware that this was an issue, nor did I know which compiler was used for Python. I'll download the Python sources and try compiling it with MinGW to see if that has any effect.

On a side note, I have cross-posted this to the PyODBC Google Group (http://groups.google.com/group/pyodbc?hl=en), as that list is more specific to the topic at hand; had I thought to, I would have posted there to begin with, simply because they are the experts on the specific subject. I did make a point of mentioning this there as well, but I still would like to apologize about the cross-post.

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

Is there any specific application for this, or are you simply trying to understand PRNGs better? Different applications can have very different requirements, above and beyond randomness, such as needing the result to be random within a given range (simply using a modulo isn't a very good solution, as it can introduce a bias).

I might add that it is often suggested that you not use a HRNG directly, but rather to use it as a source for seeds. The reasoning there is that a) not all platforms will have a HRNG, and those which do may have very different ones, so separating the source of randomness from the final generated value can be a good idea; b) even 'truely random' sources can have biases, such as the range over which the random input varies, and external interactions could potentially bias the results (a cosmic-ray shower or sunspot activity, for example, could cause a radiological detector to show a consistently higher value than background or even a fixed source); and c) you to change the pseudo-random number generator for different specifics.

One possible approach is to have a list of pseudo-random generators, and take at least three different readings from the HRNG: one for a seed value, one to select the algorithm to use, and one to set a timer for when to next re-seed the generator. This may be a bit too elaborate for practical use, as it doesn't give that much more randomness in and of …

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

I recently discussed some problems I had had in getting PyODBC working with Django and Django-pyodbc, but at the time it was decided to switch to an ASP.NET solution instead. For various reasons, we are trying once again to set up Django and PyODBC, and while we've had some success, another set of problems has arisen. At this time, running manage.py syncdb in the relevant directory results in the following traceback:

Traceback (most recent call last):
  File "C:\Python26\Lib\site-packages\AllProBugProWeb\proj\manage.py", line 11,
in <module>
    import settings
  File "C:\Python26\Lib\site-packages\AllProBugProWeb\proj\settings.py", line 3,
 in <module>
    import pyodbc
  File "build\bdist.win32\egg\pyodbc.py", line 7, in <module>
  File "build\bdist.win32\egg\pyodbc.py", line 6, in __bootstrap__
ImportError: DLL load failed: The specified procedure could not be found.

When trying to access the website, a different ImportError is raised, one which I suspect is a different problem (perhaps a misconfiguration of some sort on my part) but may still be relevant in tracking down the first issue:

Internal Server Error
An error occurred processing this request.

--------------------------------------------------------------------------------

Request handler failed

Traceback (most recent call last):
  File "C:\Python26\Lib\site-packages\AllProBugProWeb\Http\Isapi.py", line 67, in Request
    return RunWSGI(Handler, Base=Base)
  File "C:\Python26\Lib\site-packages\AllProBugProWeb\Http\WSGI.py", line 155, in RunWSGI
    Result = Application(Environ, StartResponse)
  File "c:\Python26\Lib\site-packages\django\core\handlers\wsgi.py", line 250, in __call__
    self.load_middleware()
  File "c:\Python26\Lib\site-packages\django\core\handlers\base.py", line 39, in load_middleware
    for middleware_path in settings.MIDDLEWARE_CLASSES:
  File "c:\Python26\Lib\site-packages\django\utils\functional.py", line 276, in __getattr__
    self._setup()
  File "c:\Python26\Lib\site-packages\django\conf\__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "c:\Python26\Lib\site-packages\django\conf\__init__.py", line 89, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Have you tried running the stored procedure in SSMS (SQL Server Management Studio) to see if it is the stored procedure?

Yes. The SP seems to work correctly when run manually; I confirmed this before writing the event handler.

USE [ServicePro]
GO
/****** Object:  StoredProcedure [dbo].[SetClientEmail]    Script Date: 05/26/2011 17:10:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		J Osako
-- Create date: 2011-05-25
-- Description:	Change the email address of the given 
-- account, and log the change and old email address
-- =============================================
ALTER PROCEDURE [dbo].[SetClientEmail]
    @AccountKey INT,
    @OldEmailAddress TEXT,
	@NewEmailAddress TEXT

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	INSERT INTO tblEmailChangeLog (AccountKey, OldEmailAddress, NewEmailAddress)
	VALUES (@AccountKey, @OldEmailAddress, @NewEmailAddress);

    -- Insert statements for procedure here
	UPDATE tblMainAccounts SET EMailAddress = @NewEmailAddress
	WHERE AccountKey = @AccountKey;
END

The problem appears to be in passing the parameters. Since the parameters do show up (apparently correctly) in the SQlCommand object when I watch it in the debugger, and the names in both the SP and the event handler match (I even cut and pasted the problem one out of the SP to make sure), it is hard to see how this could be.

As I said, there are other queries in which the parameters are matching correctly. The biggest difference between this one and the others (well, aside from the differing stored procedures and parameters) is that this one is an …

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

I have an event handler that is failing with an SqlException '{"Procedure or function 'SetClientEmail' expects parameter '@OldEmailAddress', which was not supplied."}' However, the code for the SqlParameter '@OldEmailAddress' is no different than that for the other SqlParameters I am using, both for this command and for others I have been able to run successfully.

protected void ChangeAddress(object sender, EventArgs e)
    {
        string newEmail = NewEmailTextBox.Text;
        if (newEmail == ConfirmTextBox.Text)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ServicePro"].ConnectionString);

            SqlCommand command = new SqlCommand("SetClientEmail", conn);
            command.CommandType = CommandType.StoredProcedure;
            SqlParameter key = new SqlParameter("@AccountKey", SqlDbType.Int);
            key.Value = accountKey;
            command.Parameters.Add(key);
            SqlParameter oldEmailAddress = new SqlParameter("@OldEmailAddress", SqlDbType.Text);
            oldEmailAddress.Value = email;
            command.Parameters.Add(oldEmailAddress);
            SqlParameter newEmailAddress = new SqlParameter("@NewEmailAddress", SqlDbType.Text);
            newEmailAddress.Value = newEmail;
            command.Parameters.Add(newEmailAddress);

            conn.Open();
            command.ExecuteNonQuery();
            conn.Close();
            Response.Redirect("~/Start.aspx");
        }
        else
        {
            ConfirmTextBox.Text = "";
            Validate();
        }
    }

I can only conclude that I am missing something important, but I cannot determine what. Any advice on this matter would be appreciated.

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

I recently explained the Python equivalent of the pointer-to-member operator here, and you may want to read through that; however, I suspect that what you want is a reference to the function itself, rather than to call the member function.

In Python, the simple solution is to use... the name of the function. That's it. If you pass the function name without any parameters, it's the same (more or less) as a pointer to a function in C++.

The real problem I see is that you're passing a method rather than a regular function, which means that you would also have to pass an object of that class along with it, assuming you don't know ahead of time the class it is meant to operate on. Alternately, you could write a function that returns a closure containing the method invocation:

New = QtGui.QAction('New',self)
    New.setShortcut('Ctrl+N')
    New.setStatusTip('New File')
    
      
    self.connect(New,QtCore.SIGNAL('triggered()'),QtCore.SLOT('lambda x: x.close()'))

Whether this will work is uncertain to me, given the way Qt passes the functions to the slot. Perhaps an explicit function would work better, I'm not sure - I just don't know enough about Qt to say. Looking at the documentation, however, makes me think that something involving the pyqtSlot() decorator would be called for, and for all I know is already part of the textEdit object you are using.

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

Would you mind telling us what the different strings represent? (My initial impression was that they were the names of genes and gene complexes, but I'm not certain.) Having some idea of what the data represents might give us some new ideas as to how to manipulate it more effectively.

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)