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

Well, it's not so much that (especially since 60 lines isn't all that much) as it is the tendency of newcomers to simply post their code without actually asking a question about it.

In this case, we'd also need to see where you are setting c_num, as well.

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

OK, let me see if I have this correct: what you want is for to provide a timer which will wait either for n milliseconds, or until a key is pressed, correct?

It sounds to me as if what you really need is to use a separate thread for the user input. One thread would sleep a given time, then pop up the message box; the other would wait for user input, and if the user does input something in the given time, perform the requested task.

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

I believe that what you are looking for is the import statement. If you have a Python file, say test.py, and wish to run the program in that source file while in the interpreter prompt, you can enter

import test

and, provided that the file test.py is in the same directory that you launched the Python interpreter from, you should be able to run the program, as well as access it's variables, call it's functions, etc. once it is imported.

Mind you, this is not the usual manner in which Python programs are run. It is more typical to have the .py files associated with pythonw.exe, which allows you to run the program just by double-clicking on the file. See the link Gribouillis posted for more details.

If, rather, you are looking to edit and test the program in question, you would be better off running IDLE (and simple integrated development environment that should have come with your Python distribution), which has a window for the interpreter prompt but also allows you to open separate editing windows for working on your source files. If you launch IDLE, the go to File-> Open File... and select your test.py file, it will open a window showing the source code; you can then run the program by going to Run-> Run Module in that window. IDLE takes a bit of getting used to, so you might consider a more powerful IDE such as Dr Python (very simple to learn …

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

The problem is that you aren't resetting either count or totalGrade before beginning the second loop. also, in both loops, you can (and probably should) move the calculation of average out of the loop body.

I think you'll also have a problem with the second loop's end condition, as you aren't changing plusStudents anywhere in the loop.

Mind you, there are ways to avoid having to have two otherwise identical loops one right after another. Has your course covered functions yet? For that matter, are you certain that these should be separate loops, as you have it here? I suspect that what you want is to nest the loops, with the outer loop being the test for whether to add more students, and the inner loop being the one to read in the test grades.

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

The issue here is that this is a pointer to the object as a whole, not just to an array; you would need to access the string's internal array to do this, and since that array is private, you cannot do that - at least not directly.

What you want to do is use the at() method to check the individual elements of the string:

bool MyStringClass::isInString(char s)
{
    for(int i=0;i<=this->length();++i){
        if(s == this->at(i)) 
            return true;
    }
    return false;
}

BTW, are you aware that there is already a method in the string class (find()) which does (more or less) what you are looking for? Just wondering.

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

As a matter of fact, I do. However, it would not be very helpful for me to simply give the code to you; learning is the goal here, after all.

I will say that you are overthinking things a bit (been there, done that, bought the tee shirt). Rather than having a conditional in which only a single character is changed between the two branches (neither of which gives you what you want), you might consider following the Sigma notation form of the series, and use a sign variable:

#include <cmath>      // add this at the top
// ...
int sign = pow(-1, i);

if you use this, and multiply the value (which will be either 1 or -1, depending on the whether the exponent is odd or even) by the result of the factorial over the difference, you can then simply accumulate the result.

result += sign * (factorial / denominator);

Another hint is to print the sign along with the value that it refers to, rather than the value before it as you have now.

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

You would use the bit? predicate to test the value first, then if it is a single bit, emit the value unchanged; otherwise, perform the split.

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

Yes. The void part only refers to the return value of the function, not the actual computation. The function runs; it simply doesn't have a return value.

BTW, strictly speaking, it should be int main() not void main(). The main() function does in fact return a value to the operating system, which is used to test the status of the program. The void main() is a common misunderstanding, often perpetuated by 'professors' who don't actually know what they are supposed to be teaching, but it is not portable and only some compilers accept it at all.

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

Does gfunc_Realloc() work correctly elsewhere? Have you tried writing a simple test program to check if the gfunc_Realloc() function behaves correctly in general (that is to say, when given some test data, it works correctly)? For that matter, are the gfunc_Realloc() and gfunc_memAlloc() in a separate compiled source file, or is it all once piece? Testing it would be much easier if they were already separate, but it should be easy enough to just copy-and-paste the necessary functions into the test program.

Also, have you checked to see if replacing gfunc_Realloc() with a direct call to realloc() works or crashes? If it crashes, does adding the fprintf() calls correct it again?

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

You would have to discuss the matter with the original coder to get a definitive answer, actually. It really has nothing to do with the BufferedReader c'tor itself, which just takes a filename as it's argument.

As for line 3, that's the beginning of an exception frame. You would need to read up on exceptions to understand the purpose of it, but let's sake for now that the try block is supposed to contain code that might have a runtime error in it; the try says that it will try to run the code, but if it throws an exception, it will halt and go to the catch statement that matches the type of exception that was raised. Exceptions are a bit tricky to understand, so if that didn't make much sense, the best thing is to wait until you've gotten further in studying the language.

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

Could you please explain what sort of problems you are having with this?

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

The first step in solving this problem, I think, is learninig to indent your code in a consistent and legible manner; since this is Java, I recommend following the official Java Style Guide, at least as far as the basics are concerned.

import java.util.Scanner;
import java.io.*;

public class prog166d2 {
    public static void main (String[] args) {
        int hours = 10;
        int wage = 4;
        int emp = 3;
        int maxemp = 6;   //maximum number of employees
        int count = 0;
        int counter = hours * wage;

        while(count <= (maxemp - emp)) {
            while(emp <= maxemp) {

                System.out.println("\nWages for " + emp + " employees\n");

                while(hours <= counter) {
                    int calc = hours * wage * emp;
                    System.out.println("For " + hours + " hours worked, the wages are " + calc + " dollars");
                    hours += 10;
                }

                while(hours == counter) {
                    hours = 10;
                }
                emp++;
            }
            count++;
        }
    }
}

Once you've done that, you'll see that your outermost loop is not actually necessary - you only need the first inner loop and the loop inside of that one. The test for hour being equal to counter is also unneeded - if it reaches that point, it is always going to be equal to counter, while on the second pass it will always be unequal. I would add that counter itself is unneeded, as it will always equal 40, though it will be different if you ever change wage; there's no actual relationaship between …

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

What is the expected result?

I suspect that you have misunderstood the last part of the summation formula. I suspect it is supposed to go more like:

         n
       ----
       \         n 
   1 + /     (-1)  n! / (x - n)
       ----
       i = 2

or,

1+2!/((x-2))-3!/((x-3))+4!/((x-4)) - ... n!/((x-n))

which means that for the example given, it would be

1+2!/((x-2))-3!/((x-3))+4!/((x-4))-5!/((x-5))

Note that if n is less than 4, the formula goes shorter than the example given. So, for example, for n = 3, the formula would simply be

1+2!/((x-2))-3!/((x-3))

The practical upshot of this is that you need to compute the sum using a loop.

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

As per request, one boilerplate answer coming up:

First off, we don't do other people's homework for them. Second, we don't do other people's homework for them. And third, we don't do other people's homework for them. Sensing a pattern here yet?

No one here will simply hand you a solution on a silver platter. If you show us what you've done, what you've tried to do, and what problems you've had with it, then we'll be happy to help. If you have specific questions, we can answer them, or at least point you in the right direction. If you have a program with a bug you can't swat on your own, we'll be glad to assist, so long as you pay attention to the forum rules and post sensible questions in an intelligent manner that we have some reasonable hope of answering.

But just cutting and pasting an assignment into a message, without even prefacing it with something like, "I have this homework problem that I can't solve...", is likely to get you booted from the message boards here and elsewhere - if you're lucky. What happens to you if you are unlucky is... well... let's just say that this guy probably won't be trying that again, on that forum or this one.

And in case you think you won't get caught... think again.

We take this issue seriously here. Very seriously. Asking us to do homework for you is a grave breach …

rubberman commented: Loved the thread about "this guy"! :-) +12
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Before addressing your question, I would like to point out some issues with the code as given, ones which may help understand the problem at hand. Before I do, would you mind telling us what compiler and IDE you are using? It may help us understand certain aspects of this better.

First off, your header declarations are all over the place. Your <cstring> and <fstream> declarations are correct for modern C++, but <iostream.h> is an obsolete version of the header; it should now be just <iostream>. As for <stdlib>, this is simply incorrect; the C++ header for the C standard library is <cstdlib> (note the 'c' at the beginning of the library name).

Second, while many compilers do accept void main(), strictly speaking, only int main() is correct. The reason for this is because programs do in fact return an integer value to the shell, so the declaration must reflect this.

Third, the indentation of your code is, to be blunt, a mess. You want to be both careful and consistent in how you indent you code. Now, it may be that some of this comes from using tabs in some place and space in others, something you may not have control over; but if you can, you should configure your editor so that it only uses one or the other for indenting, not both.

Fourth, if your file output, 'GSP.xls', is actually meant to generate an Excel spreadsheet (as the extension implies), then trying to write it the way …

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

The short answer is, you can't. NASM is specific to the x86 and x86-64 family of processors; you will need a Z80 assembler (that's the processor the TI-84 uses) which produces object code which can be loaded to the calculator in order to program for it. The TASM you mentioned (by which I assume you mean Telemark Assembler, not Turbo Assembler) is pretty much the only one which fits that bill.

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

One of the more common functions in any language is conversion of an integer to a string. This implementation, which demonstrates not only the common function activation record format but also a simple recursive function, was written in response to a recent question in which the OP posted an incomplete implementation; this should show how such a function could be written for the MIPS processor.

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

Macros, like all preprocessor directives, are expanded before the compiler is run; thus, no, you cannot override a macro definition with a C language statement.

A bit more explanation may be in order here. When you go to compile a program in C (or C++), you are actually invoking at least two different programs (conceptually, anyway; not all C compilers work quite this way, but all have the same stages), each of whose output is piped to the next. The first program is call a preprocessor, which performs a series of textual transformations on the source code and passes the result on to the compiler proper. The preprocessor is, in effect, a separate language translator, which goes through the source code searching for the tokens of this sub-language in order to process them. In the case of a macro, what the pre-processor does is seach for the defined macro names in the source file, and replace them with the text of the macro. Thus, when you have the lines

#define BUFFEFR_SIZE 5

char buffer[BUFFER_SIZE];

The preprocessor replaces it with the code

char buffer[5];

Parameterized macros are only a little more complex:

#define MIN(x, y) (((x) < (y)) ? (x) : (y))

int foo = 17;
int bar = 23;
int quux;

quux = MIN(foo, bar);

becomes

int foo = 17;
int bar = 23;
int quux;

quux = (((foo) < (bar)) ? (foo) : (bar));

Note all the parens around each sub-statement, …

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

This posting may help explain the purposes behind the stack instructions a little better.

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

The problem is actually two-fold: first, you are loading a value where you need an address; and second, you are trying to write out an integer with a function which expects a character buffer. The solution to the first problem is to change the code so that it puts the value into a character buffer, then gets the address of said buffer for the syscall argument:

    .data
fout:   .asciiz "testout.txt"      # filename for output
buffer: .resb 33                   # set aside a space of 32 characters

    .text

li $t0, 1
li $t1, 2
add $t3, $t0, $t1
la $t0, buffer
sb $t3, ($t0)

###############################################################
# Open (for writing) a file that does not exist
li   $v0, 13       # system call for open file
la   $a0, fout     # output file name
li   $a1, 1        # Open for writing (flags are 0: read, 1: write)
li   $a2, 0        # mode is ignored
syscall            # open a file (file descriptor returned in $v0)
move $s6, $v0      # save the file descriptor 
###############################################################
# Write to file just opened
li   $v0, 15       # system call for write to file
move $a0, $s6      # file descriptor 
move $a1, $t0      # address of buffer from which to write
li   $a2, 44       # hardcoded buffer length
syscall            # write to file
###############################################################
# Close the file 
li   $v0, 16       # system call for close file
move $a0, $s6      # file descriptor to close
syscall            # close file
###############################################################

This still leaves you with the problem that …

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

Is there any particular part you are having trouble with?

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

Before we go anywhere with this, I want you to be clear about two things. First, that this is actually two different programs which you'll need to write, and second, that you will need to be the one to write them. We can give advice and help, but we cannot and will not write the program for you.

Having said that, let's start with what you do know how to do. Can you write a simple class layout, and declare the various local and instance variables you will need for the first program?

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

The problem isn't in the comparison, nor in the je or jne instructions; it is in the declarations for a and b. For each of those, you define them as a 2 reserved bytes; howvever, the mov eax, [a] instruction assumes that a is a doubleword (4 bytes), and as a result, it reads in the combined bytes of both a and b. The mov ebx, [b] is even worse, because once again, it expects a double word, and this time it loads b into the high word of ebx, and whatever garbage happens to be following b in the executable into the low word. You want to define both a and b as resd 1 instead.

Actually, there's still a serious problem with the program: while it will now seem to work, provided you use values no more than 3 digits long, it isn't actually doing what you think it is. The problem lies with how you are reading in the values, and what you are actually comparing. When you read in the value of a (for example), you are using the sys_read call (the system call where eax equals 3). This call reads in a string of a given size. Then, as the program is now, you are using that string value as the basis of a 32-bit comparison. This will seem fine if the value fits into 4 bytes (which means three digits and the hidden newline character), but it isn't really comparing the numeric values. It …

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

As a piece of advice, I can suggest this: assuming that the language you are indenting is C (or one with a similar block syntax, such as Java or C++), then the simplest solution is:

set the indent amount to four
set the indentation level to zero
for the length of the file:
    read the next char
    if the char is a newline:
        insert the newline
        insert (indent amount * indentation level) spaces
    else if the char is a whitespace:
        discard it; 
    else if the char is an open brace:
        insert a newline
        insert the open brace
        increment the indent level by one
        insert a newline
        insert (indent amount * indentation level) spaces
    else if the char is a close brace:
        insert a newline
        decrement the indent level by one
        insert close brace
        insert a newline
        insert (indent amount * indentation level) spaces
    else:
        insert the char as is

if indentation level is still more than zero, emit an error message

Now, this is just a rough method, and doesn't properly handle some edge cases (e.g., struct definitions), but it should be enough to get started with.

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

In the declaration of struct author, you define down as type link, which is a typedef for struct author*. What you actually want is for it to be a ptr (that is, struct book*). Thus, you'll want to move the typedef of type ptr up to before the definition of struct author, and change link down; to ptr down;.

typedef struct author *link;
typedef struct book *ptr;

struct author
{
       char name[20];
       link next;
       ptr down;
};
typedef link LIST;
typedef link pos_author;


struct book
{
       char title[20];
       int year;
       int page;
       ptr down;
};
typedef ptr pos_book;

Oh, and you misspelled 'title', BTW. HTH.

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

@gwolf1: The link which Deceptikon provided - which I will repeat here - gives detailed explanations and code samples for managing different sorts of hash tables. It should give you enough of an overview to get you started, and would surely do a better job than we could do by attempting to answer you on the fly.

Some additional links which may prove useful:
+ Wikipedia: Hash Table
+ Wikipedia: Hash Function
+ Wikibooks: Hash Tables
+ Hash Tables
+ Literate Programming: Hash Table in C
+ Simple C Hash Table Example

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

The ampersand actually marks the character which is to be used as the hotkey; if you look at the menu as it actually is rendered, you'll see that those letters all are underscored. In the case of 'Exit', the 'x' is the hotkey character (that is to say, if you hit ALT-X, it would cause the program to exit), so the ampersand is directly before it. It only seems out of place because all of the other items have hotkeys with the first letter of the word, but this does not need to be the case, as you can see.

As for why 'x' is used for exit rather than 'E', it is because, according to the Windows style standard, Alt-E is used as the hotkey for the Edit menu, even if it isn't present in the application.

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

As an aside, you will want to use int as the return type of main() in the future. Strictly speaking, void main() isn't legal C++, even if some compilers accept it. Just a piece of advice, which you may need to know about as most newer compilers will flag void main() as erroneous, or at least give a warning.

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

Rather than sharing the code this way, which has some serious disadvantages (no versioning, having to manually cut and paste the code into place, risking overwriting the good code with the older code, etc.), I would suggest finding a source repository such as SourceForge or GitHub and share your code through that. The advantages are multiple, as you'd be able to easily track what changes were made when, and by whom; have multipled separate lines of development for testing purposes; be able to merge changes from several different people; and so forth. Believe me, once you've worked with a decent distributed version control system, you won't want to do any project without it.

Of course, this assumes an open-source project; but then again, you'd hardly be posting your code here if it weren't, would you? Even if it is meant to be closed-source, most source control sites allow you to set up a private, members' only repo, though it usually costs money.

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

Rithish: The issue is not in the behavior of the two forms of the function, but rather is in the wording of the C language standard, and less directly, in the behavior of the majority operating system shells. You see, it isn't incidental that main() was type int even in the days of default return values; it was intentional behavior. The return value of the program isn't simply discarded, it is returned to the program which initiated the program run, usually the command shell.The returned value is used as an indicator of the program completion status - 0 means it ran to completion without any fatal errors, any other value indicates that something went wrong. In Unix (and it's descendants, Linux and MacOS X), there is even a standarsd list of error messages one can return, though it is rarely used.

The value isn't always, or even often, used, though it does play an important role in shell script programming, where a half dozen or more different programs may be run by a single script, any of hich could, theoretically, fail.

Also, not every OS uses the value in a meaningful way. Windows doesn't generally do anything with it, though it is capable of it for batch scripting; most embedded systems don't have anything to return to, or else have some less generic method of catching errors.

Prior to 1986 or so, this wasn't a big deal, because it was stadard practice to use a default return value, like this:

deceptikon commented: Nice. +9
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

In addition to what Deceiptikon and sepp2k said, I would add that it yu've declared the function as returning an int value, but at no point to you actually return one.

There is actually a much simpler way to do this, one which takes only the starting value as an argument and returns it's factorial. If you think through the definition of a factorial, it is

N! = N * (N-1)!

which could, as an example, be expanded to get

N! = N * (N - 1) * (N - 2)!
N! = N * (N - 1) * (N - 2) * (N - 3)!
N! = N * (N - 1) * (N - 2) * (N - 3) * (N - 4)!

and so forth, eventually giving

N! = N * (N - 1) * ... 1

meaning that all you need to do to calculate N! is to first calculate (N - 1)!, then multiply that by N. From this, the answer should be straightforward: just re-write the definition into C code.

int factorial(int x)
{
    if (x <= 1)
        return 1;
    else
        return ???   // insert factorial definition here, in C code
}

This should be very easy to understand and implement; I've given you more than enough, too much very likely, and will leave the remaining half a line of code to you.

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

EDIT: I originally thought that this was a different problem, but then I noticed that you were, in fact, reading in a number and not a character. My error.

Looking over the code again, it's simply that you aren't putting break; statements at the end of each case of the switch().

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

Ah, now that would depend on the compiler you're using, at least to some degree, and whether you were using a framework of some kind (e.g., .NET, MFC) or calling Win32 directly. To start with, you would need to use a modern Windows compiler, so Turbo C++ isn't an option. Second, if you used a compiler other than Visual C++, you would need to use Win32 directly, or a third party windowing library such as Qt or wxWidgets, as the most common frameworks (MFC and .Net) are specific to Microsoft's compilers. Third, you'd need to be familiar with how to write a Windows application in general, which is quite different from writing a console application.

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

First off, you should always use int as the type for main(), not void. While some compilers allow for other return types, the only really correct (in the sense of portable and matching the standard) declaration is int main() (or, when using command-line arguments, int main(int argc, char* argv[])).

Second, you don't #include the necessary headers, at least not in the sample of code you have given us. This is important because you also re-declare a function free() which is significantly different from the Standard C free() declared in <stdlib.h>. If you had included the headers, your com[piler should have given a multiple declaration error.

Third, the argument passed to malloc() is simply erroneous; you are allocating what you assume to be the size of a pointer (though it would actually depend on the system and compiler), but are returning it to the elements of an array of pointers to struct mem_chunk, which is significantly larger than 4 bytes long. Assuming you intended to populate the array with struct mem_chunk structures, the correct call should be:

 temp[i]=malloc(sizeof(struct mem_chunk));

Even if your intent was to populate the array with pointers to pointers (which is not what it is declared as), you would need to call it as

  temp[i]=malloc(sizeof(ptr));

because the size of a pointer will vary depending on system and the compiler.

In any case, you aren't actually creating a linked list at any point in the program; instead, you are creating an array of …

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

Assuming you are running Windows, the answer is, you don't. DOS TSRs required low-level access to the BIOS, and hooking an interrupt; they are notoriously badly behaved under Windows, even inside of the cosnole or a DOS box.

Under Windows, then the equivalent of a TSR is simply a program that launches without opening a window, and waits for the appropriate invocation. Usually, what you would do is put an icon in the system tray, and wait for it to be clicked to access the program. The 'classic' TSR invocation method of using some specific control-keystroke is discouraged, as it could conflict with other programs which use the same keystrokes.

Can you tell us more about the purpose and goals for this program, and why you want it to behave as a TSR?

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

What it comes down to is that each state transition can have it's own behavior, represented by a function. In this case, all of the states use the same function to handle the different states, but that is just to keep the code simpler; in practice, you would probably have one function for each state transition.

You may want to compare this to another FSM design which I came up with for a compiler class some years ago. It is also in Python, and while the two have some striking similarities, they also have significant differences as well.

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

@Thekilon: You should check the dates of a thead before posting to it. The original conversation ceased over nine months ago.

For the record, in the unlikely case that the original poster is still interested in this thread, I believe that by 'punch cards' the OP is referring to machine code, the specific encoding of CPU operations in binary. Few if any programs have been written this way since the late 1940s, after the first assembly languages were introduced, though in the 1960s and 1970s it wasn't uncommon to have to toggle in a small machine code bootstrap program when starting a computer. I find it unlikely that any Pascal compiler was ever written in machine code directly, and very few were written in assembly language (one that I can think of was the original Turbo Pascal, but that was very much of an unusual case even in the early 1980s). The majority of Pascal compilers have been self-hosting, as pyTony stated, using either a cross-compiler or a p-code interpreter to port the compiler to new systems when needed.

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

That depends. Just how do you intend to use them? We really would need more detail to give you useful advice.

If you simply need a reference, the this should do nicely; while that site is for C++ rather than C, the C I/O libraries work the same in both languages, with the sole important difference being the name of the header file (<stdio.h> in C, <cstdio> in C++).

If you need more about the use of the functions, you would do well to search for a tutorial, such as this one.

Read through the documentation and one or more of the tutorials, then come back with specific questions if you still aren't sure how it works.

I should mention that there is no function in the standard library for deleting files; that is an operating system specific action, and you'd need to check into system calls for you paticular OS in order to find out how to do that. The same applies to renaming a file.

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

To answer to OP's question, the exact use of bit fields is to allow you to pack several small values into a single integer value, by defining the values in terms of how many bits they need in order to be stored efficiently. As Deceptikon said, they are primarily useful for things like flags, which take only one bit each, or for small integer values.

The main downside to bitfields is that the exact order in which the bits are stored is compiler-dependent, as are other related issues such as the size of an int value. This means that some of the most desireable uses of them - representing the fields of an I/O port, for example - aren't portable. Now, this may actually be less of an issue than it sounds, since most of these uses are system-dependent anyway, but it does mean that anything that isn't system-specific cannot use bitfields without losing portability.

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

OK, we can see that you have these two programs written, but what have you done about the current assignment?

BTW, three things to take note of. First, you should always declare main() as type int; while void main() is accepted by some older, non-standard compilers, it is not actually correct according to the C++ standard, and never has been acording to Bjarne Stroustrup. Second, in modern C++, the header should be <iostream>, not <iostream.h>; however, since it appears you are using the ancient Turbo C++ compiler, and probably don't have a choice in the matter, you can only do what you are doing for the time being. Third, you use the non-standard <conio.h> library, which is not part of the actual C++ language and is not supported by modern systems.

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

Assuming you are using Python 3.x, then the input isn't going to be a tuple of separate strings, but one whole string. This means that you'll need to use .split() on the returned string in order to get the separate tokens.

def shell():
    in_string = input ('> ')
    tokens = in_string.split()
    if tokens[0] == 'ECHO':
        [print(x, end=' ') for x in tokens[1:]]

Mind you, this will only work if the enter value is exactly 'ECHO', all caps. THis probably isn't what you wanted, but I'll leave it to you to make any corrections of that sort.

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

I'll put my two cents in by repeating my earlier recommendation in a similar thread: Try walking through the process outlined in Scheme from Scratch. It is a few weeks of work for the basic implementation, but it is always possible to continue refining it.

If that's too much right now, try making an implementation of Conway's Game of Life cellular automata. A simple text implementation may take only a few hours, but there are endless ways to elaborate upon it, especially if you implement Gosper's HashLife algorithm. It's also tremendous fun if you haven't played around with it before.

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

what code would I have to use in the bootloader to open the second file?

That depends on what kind of filesystem you are using, and what executable format the file is in. For example, my own original boot loader simply assumed that the second stage was in sector (0, 1) of a floppy disk, and was simply a binary image which could be loaded directly into memory and jumped to from the boot sector; however, that design has definite weaknesses, starting with it being dependent on the type of disk it was booting from.

A (slightly) more practical solution is that used in the classic FAT design: the size of the second-stage boot loader is given in the BIOS Parameter Block, a section of data at the beginning of the FAT boot sector, in the 'reserved sectors' field. The second stage is a binary image, just as before, but it can be of an arbitrary size defined in the BPB.

A better solution still would be that used in later versions of FAT, and in most other systems, which is to write just enough code to find the secondary file in the file system and load it. The problem there is that this can easily exceed 512 bytes, which is exactly the position you are in now.

If you haven't already done so, I would recommend reading the Bootloader Theory, Boot Sequence, and Roll Your Own Bootloader

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

That depends on a) the operating system (and window manager) you are using, and b) whether you are free to use third party libraries. There are no C standard libraries that address graphics, or indeed any form of I/O other than buffered streams; however, there are many different 3rd party graphics libraries, some of which are portable across multiple environments, such as GTK+, Qt, and wxWidgets.

OTOH, if you only need to support, say, Windows, you could use the native Win32 API (or its Win8 successor, WinRT), which provides the primitives for graphics and window management. However, Win32 programming is a bit of an uphill battle, and the usual frameworks needed for Windows development (MFC, .NET) are specific to the Microsoft development tools.

My recommendation is to choose a widget toolkit, and use that, rather than trying to program in the Win32 API directly; not only is it going to be easier, it will allow you to write programs that are portable across Linux and MacOS, which is a definite plus.

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

Let's see if you I have this correct. You have a web page with a server-side Python script which extacts data from a database and is supposed to pass it on to the client. On the client side, you need to have a dialog box come up and request a location to save the data file to, then once the request is complete, it should save the file to the location given. Is this correct?

The problem here is that the Python script is running server side, not client side, and there really isn't a way to get a Python script running client side that I can think of. I would expect you'd need to use at least some small amount of JavaScript or some similar client-side scripting in order to do what you want.

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

With an 8-bit division, the dividend is held in AX, with AH being the high bit and AL being the low bit (naturally enough). This means that you need to have a suitable value in both AH and AL before dividing.

In this case, since you are only dividing one digit numbers, the best solution is to simply clear AH:

    MOV CL, AL
    MOV AL, BL
    MOV AH, 0      ; clear AH

    ; divide
    DIV CL
    MOV NUM1, AL
    ADD NUM1, '0'
    MOV NUM2, AH
    ADD NUM2, '0'

There may be other issues with the code as well, but that is the one which stands out to me.

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

A WORD value is a 16-bit unsigned integer type used in Windows. Since it is actually only a typedef of unsigned short under the current Microsoft VC++ library, Assuming you are using standard C++ strings, it should be possible to use an stringstream to convert it to a string.

std::stringstream convert;
std::string numday;

convert << SysTime.wDay;
convert >> numday;

I cannot guarantee that this will work using other compilers, however.

Now, I noted that you have the type of numday as String, (note the capitalization), which is not the same as the standard string class. Was this a typo, or are you actually using a different string class?

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

The shell command you are looking for is g++ filename -o executablename, or at least that will get you started (the '-o' stands for 'output', and let's you choose the name of the final executable). Look up the documentation on GCC and make for more involved compilation.

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

My initial impression is that this is in a serialization format known as JSON (JavaScript Object Notation). However, it has additional characters - 'D's and 'H's - following some of the fields. Also, knowing the format doesn't tell you much about the specific meaning of the fields. Sorry I couldn't say more.

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

Ah, thank you for that correction.