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

You sholdn't need to; it is part of the standard Python library. I gather you were unable to use it? What version of Python are you using? What exactly happens if you enter the following into the Python interpreter prompt?

import random

random.randint(0, 6)
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The first one is simply a misspelling in the definition of the showKilometers() method.

The second is that you declared showFeet() ad type void, when it should in fact return a double.

On a related not, you need to have the actual return statements in the three 'show' functions:

  public static double showKilometers(double meters)
  {
    return meters * 0.001;

  }
  public static double showInches(double meters)
  {
    return meters * 39.37;

  }
  public static double showFeet(double meters)
  {
    return meters * 3.2; 
  }

HTH.

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

While I don't know much about shellcoding in general, I did find this FAQ Illuminating fnord. Questions 6, 7 and 10 seem particularly relevant to your problems. After the FAQ portion, he includes a tutorial that has it's own version of the 'Hello' program, which seems to be written to avoid the NULL byte problem.

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

There is also an Objective-C front-end for GCC that is available on any platform that support GCC, so it is certainly available for Windows.

The interesting thing is, Objective-C actually predates C++ by about a year, at least as a publicly available language ('C with Classes' was in development as early as 1979, but wasn't released as C++ until 1983). Both languages began as preprocessors on C, with C++ being derived from Simula, and Objective-C from Smalltalk. Indeed, it is safe to say that Objective-C began as little more than embedded Smalltalk statements in a C language context.

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

You mention that it is running under Linux, but you don't mention for what processor. I'll assume that it is meant to be 32-bit x86 code for now, but if it is for, say, a Raspberry Pi (which uses an ARM chip), or even just the AMD64 mode of an x86 processor, then my comments may not be correct.

If I am disassembling this code correctly, it comes out to the following (hex on the left, AT&T mnemonics in the middle, Intel mnemonics on the right):

ba : 0e 00 00 00   mov.l 0x0e, %edx       :  MOV EDX, 0Eh
b9 : 04 90 04 08   mov.l 0x08049004, %ecx :  MOV ECX, 08049004h
bb : 01 00 00 00   mov.l 0x01, %ebx       :  MOV EBX, 01h
b8 : 04 00 00 00   mov.l 0x04, %eax       :  MOV EAX, 04h
cd : 80            int  0x80              :  INT 80h
bb : 00 00 00 00   mov.l 0x00, %ebx       :  MOV EBX, 0
b8 : 01 00 00 00   mov.l 0x01, %eax       :  MOV EAX, 1          
cd : 80            int  0x80              :  INT 80h

It looks like all this is doing is passing a string to the screen print syscall, followed by the system exit syscall. Nothing exactly fancy, except... where is the char pointer in ECX actually pointing? The memory location it is referencing is hardcoded, but you don't actually have anything at that location, at least not in the current process. That by itself is likely to cause a segfault, even if the code were in an executable page.

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

As Rubberman alluded to, on modern processors, memory is not unitary. Most CPUs today break memory up into pages - blocks that can be manipulated my the hardware memory mangaement system - and mark the individual pages as to whether their contents can be modifed or not, and whether they can be executed or not. Generally speaking, any variables are going to be in memory marked as non-executable, and attempting to execute code within them will indeed cause a memory protection violation. The same is true of constants, in which case the page is also marked as non-writeable.

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

Odd, I have that code running flawlessly on my system. What version of Python are you using?

Can you check the code again, to make sure you didn't drop anything? I am specifically thinking that you might not have included the first line (hit = None), which is important in that it resets hit after the bullet is removed from the list.

Also, try changing bullets[index] to bullets[hit]. It may be that index is going out of scope, though I would expect that it would give a different error were that the case.

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

The simplest solution here is just to remove said bullet from the list bullets.

    hit = None

    for index, bullet in enumerate(bullets):
        crect = pygame.Rect(bullet[0] - 3, bullet[1] - 3,3*2,3*2)
        shoot = pygame.draw.circle(screen,(255,255,255),(crect.center),3)
        if crect.colliderect(Boss):
            print('hit')
            hit = index

    if hit is not None:
        del bullets[index]
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

As for your question about heap memory, this post should help clarify how memory is allocated and used. It is written from a C/C++ perspective, however, so there is more to be added about it.

The first thing you need to know is that objects in C# are always in dynamically allocated memory. This makes it possible to add or remove objects freely, without having to worry about the space involved. But what happens when you run out of memory? Well, I'm going to get to that in a bit, but there are a few things to explain before I get to that.

The next thing is that there is a difference between a variable and an object. In C# (and many modern languages), a variable of an object type is not an object itself, but rather a reference to an object. This is in contrast to a variable of one of the primitive types (int, char, float, etc.), or of a struct type, where the value of the variable is the actual value being worked on. The value of a object type variable is a reference to where the object is in dynamic memory. A variable can itself be part of an object, or be part of a class; the former are called instance variables, while the latter are static variables or class variables. When you invoke the constructor of a class, you are actually allocating memory for the new object, after which the c'tor itself is …

ddanbe commented: Good explanation. +14
silvercats commented: Exactly the answers I am looking for. +2
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You presumably would use get_rect(), the same as with the other sprites.

I'm in a bit of a quandary about how to help you, as I've more or less completely re-written the program for my own amusement, and I'm not sure if what I've done would apply to your code in any meaningful way. My code really does depned on using classes, and specifically, inheritance. My current version has a base class, GameObject, that itself is derived from pygame.DirtySprite (which in turn inherits from pygame.Sprite), and is the parent class of the Player, Enemy, and Bullet classes. I relies on the pygame.sprite.RenderUpdates collection class to draw the sprites, and uses the collision detection in the parent pygame.Sprite class for determining of the bullets hit their target. Unrolling all this to procedural code is not a viable option.

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

You might want to look into using the PyGame Sprite class for the bullets, as it includes built-in colission detection. For that matter the regular Rect class has several collision detection methods which could be of use, though they aren't as fine-grained as the Sprite methods are.

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

Unfortunately, I don't have any site to try telnetting into, so I can't reproduce your problem. If I knew where you were trying to get to (the address you are using is a local one, not a global Intenet address), I could try telnetting into the same site, but unfortunately that probably isn't possible to do from outside of your local network.

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

Basically, what it comes down to is that you have both of the return clauses inside of an if/else statement, and the compiler does not have the ability to determine for certain that at least one of the options is guaranteed to run.

The solution in this case is simple: get rid of the else clause, and move the second return clause to the end, after the last of the for loops exits.

    public boolean isFine(){
        for( int i = 0; i < myarray.length; i++ ){
            for(int j = 0; j < myarray[i].length; j++ ){
                if( myarray[i][j] == myEnumeration.FRIDAY ){
                    return false;
                }
            }//end of column array
        }//end of row array 
        return true;
    }//end of isFine()

This is actually necessary anyway; with the original version, the function would have exited on the first pass of the inner loop one way or the other, when what you presumably wanted was for it to return true if no cases proved to equal myEnumeration.FRIDAY.

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

In the first set of declarations, the variables are local to main(); they only exist inside main(), and only for the time that the program is running. You can print the variables from main() just as you have them now.

In the second set of declarations, the variables are instance variables; they would exist within the scope of an object declared as that type, and each object would have their own versions of the variables. They would not be visible in main() as written, as main() is a static function and can only see variables that are local to it, or have been declared static as part of the class. To access the instance variables, you would need to instantiate a variable of the class, and access them from that object:

public class myclass{
    boolean variable1 = false;
    boolean variable2 = false;

    public static void main( String args[] ){
        myclass myobject = new myclass();
        System.out.print(myobject.variable1 + " and " + myobject.variable2);
    }
}

(Note the way I indented the lines inside of main(), BTW; as a rule, you want to indent every level of nesting, and dedent when the nested scope ends.)

To declare the variables as class variables, you would need to use the keyword static in their declarations, just as you do with class methods.

    public class myclass{
        static boolean variable1 = false;
        static boolean variable2 = false;

        public static void main( String args[] ){
            System.out.print(myclass.variable1 + " and " + myclass.variable2);
        }
    } …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Hmmn, here's an old trick that may be appropriate here: drop the first letter of the words you are matching against, such that you are waiting for 'ogin:' and 'assword:'. The reason this may work is because the first letters may or may not be capitalized; if you assume capitalization when there is none, or vice versa, you may end up waiting indefinitely.

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

COuld you please give us some more information about the way the program is failing, e.g., error messages, the stack trace, and similar information? Also, what version of Python are you using? The code you posted is for Python 2.x; if you are running Python 3.x, it would fail, because several things have been changed or removed since the older version.

Also, are you certain that the host you areconnecting to has a Telnet service running? Most desktop or workstation systems have Telnet disabled by default.

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

Hmmn. Can you go into more detail about what you are trying to do? It is very unusual to need (or even want) pixel per pixel access to the a bitmap, and the particualr goal is important. Are you trying to alter the image as it is loaded into video memory, or the file, and if the former, do you need to save it back to the file again later? Put another way, is this a matter of editing the file, or of modifying the image as it is shown, or both?

I'll assume that this is under Windows; I know you don't use Macs, and under Linux you would use libbmp, as previously mentioned.

If you need pixel access to an image being displayed, then it doesn't matter what sort of file it came from; you would use GetDIBits() and SetDIBits() if you are working with the GDI library directly, or else you could use the Bitmap class of the GDI+ class library, which has the methods GetPixel() and SetPixel() for this purpose. (I am assuming you want to avoid C++/CLI.)

Even with Windows, libbmp is an option, if you are using MinGW and GCC. That may be the easier solution, as the library is platform-independent and avoids a lot of the details of Windows image handling that you would otherwise be facing. Note that it only works with uncompressed files, AFAIK. The …

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

If it helps any, here is what I've come up with so far in implementing your class:

bitmap.h

#ifndef BITMAP_H
#define BITMAP_H 1

#include <exception>
#include <iostream>
#include <iomanip>
#include <fstream>


const unsigned short BMP_MAGIC = 0x4D42;

class bmp_format_exception : public std::exception
{
public:
    virtual const char* what() const throw()
    {
        return "Bitmap format not valid.";
    }
};


class file_write_exception : public std::exception
{
public:
    virtual const char* what() const throw()
    {
        return "Unable to write to file.";
    }
};


class BitmapImage
{
    struct
    {
        unsigned short headerField;
        unsigned int fileSize;
        unsigned short reserved1;
        unsigned short reserved2;
        unsigned int startAddress;
    } BitmapFileHeader;
    struct
    {
        //probably a union of the different possible header structs???
    } DIBHeader;
    struct
    {

    } ExtraBitMasks;
    struct
    {

    } ColourTable;
    unsigned int gap1,gap2;
    struct
    {

    } PixelArray;
    struct
    {

    } ICCColourProfile;
public:

    friend std::istream& operator>>(std::istream& is, BitmapImage& bmp)  throw(bmp_format_exception);
    friend std::ostream& operator<<(std::ostream& os, BitmapImage& bmp)  throw(file_write_exception);
    void printHeaders();    // used mainly for debugging purposes
    int width();
    int height();
    unsigned int &operator()(int x, int y);//pixel access
    unsigned int alphaMask();
    unsigned int redMask();
    unsigned int greenMask();
    unsigned int blueMask();
    unsigned int bpp();
};

std::istream& operator>>(std::istream& is, BitmapImage& bmp)  throw(bmp_format_exception);
std::ostream& operator<<(std::ostream& os, BitmapImage& bmp)  throw(file_write_exception);
#endif

bitmap.cpp

#include <iostream>
#include <iomanip>
#include "bitmap.h"

unsigned short char2short(unsigned char upper, unsigned  char lower);
unsigned int char2word(unsigned char upper, unsigned char middle, unsigned char lower, unsigned char lowest);

inline unsigned short char2short(unsigned char upper, unsigned char lower)
{
    return (static_cast<unsigned short>(lower) << 8) | static_cast<unsigned short>(upper);
}


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

Oops, I forgot to say, while you certainly can use the C-style file functions, I don't think there is any reason why you can't use the C++ iostreams as well. While the C++ I/O may require some additional effort to get it to do what you want, it actually is more flexible than the C functions are. Either way, just remember to open the file as binary rather than the default text mode.

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

There really isn't any formal definition of the format, unfortunately, at least not one that Microsoft has seen fit to share with anyone. Their own recommendation is to always use their library functions to manipulate BMPs, and any other approach is likely to be incomplete, as they deliberately keep the full details from other programmers - and a full implementation might be in violation of one or more patents, either Microsoft's own or ones they have licensed. Who knows? MS isn't telling...

My recommendation is to look into the code for libbmp. It's probably the best resource available on the format outside of Microsoft themselves.

I'm guessing you've seen these links already, but in case you haven't, here are some resources to follow up on:

The libbmp repository (probably the closest thing to a complete 3rd party implementation):
https://code.google.com/p/libbmp/

Official MS documentation:
http://msdn.microsoft.com/en-us/library/dd183391.aspx
http://msdn.microsoft.com/en-us/library/dd183386.aspx
http://msdn.microsoft.com/en-us/library/dd183383.aspx

DDJ article on the format:
http://www.drdobbs.com/architecture-and-design/the-bmp-file-format-part-1/184409517
http://www.drdobbs.com/the-bmp-file-format-part-2/184409533?pgno=5

Other links:
http://www.fileformat.info/format/bmp/egff.htm
http://www.faqs.org/faqs/graphics/fileformats-faq/part3/section-18.html

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

You will need to you double indirection, i.e., a pointer to a pointer.

#include<stdio.h>

void swap(char **a,char **b);

int main()
{
    char *p[2]={"hello","good morning"};
    swap(&p[0],&p[1]);
    printf("%s %s",p[0],p[1]);
    return 0;
}

void swap(char **a,char **b)
{
    char *t;
    t = *a;
    *a = *b;
    *b = t;
}

Not entirely obvious, but simple enough once you see it.

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

What have you got so far?

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

OK, though I would consider this: It only took me about four hours to re-write the code to use classes for the whole program, including the changes to the event handling and the movement. More importantly, I wrote the base class for all the game objects in about 20 minutes, and then extended that for the Player class in most of the rest of that time (that being the most complex of the classes). Once I had that, the Enemy class took about 10 minutes, because the majority of it was already present in the parent class.

I know it would take longer for you, since you aren't familiar with classes, but I assure you, they would end up saving you a lot of headaches, time, and effort.

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

It isn't necessary, but yes, I would recommend it, as Eclipse is a good IDE for Java and there are add-ons specifically for making it effective with Android development.

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

First off, you should know general Java programming, as Android is based on Java. I would start with Oracle's Java Documentation, and a good book on the topic such as Thinking In Java (if you can't afford the e-book, the previous edition is available for free). You will also want to pick up the Eclipse IDE and learn how to use it, as it is the best suited for Android development.

Once you've got a decent grasp of the basics of Java programming, then you'd want to pick up the Android SDK, for developing your apps, and set up the Android emulator, for testing them. I would also recommend reading Learning Android as aan introductory textbook, followed by Programming Android in the same series.

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

The main issue is actually with your format string; for month, you should use capitalized letter M. Similarly, for 24-hour time going from 00 to 23, you need to use capital H. To get the time zone in the format you want, use the capital letter Z twice.

"MM.dd.yyyy HH:mm:ss ZZ"
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

One thing I would recommend also: you don't need to read the image files each time you want to change the image or BLIT it; you can save the images in variables and simply copy it to the current variable when you need to. In my version, I have it initialize the master cpoies at the time when the class is built, and then simply pass a reference to it to each of the individual objects, The relevant part of the Enemy class, for example, is

class Enemy(GameObject):
    front_src = "Boss.png"

    def __init__(self, screen):
        try:
            front = pygame.image.load(Enemy.front_src)
        except:
            print("Could not load enemy image")
            exit(-1)

The object in front is passed to the c'tor of the parent GameObject class, which stores it for later use. It uses a little more memory, but cuts down on the disk accesses, making the game more efficient. The Player class extends this with image_right and image_left members:

    def __init__(self, screen):
        try:
            front = pygame.image.load(Player.front_src)
        except:
            print("Could not load player front image")
            exit(-1)
        try:
            self.image_left = pygame.image.load(Player.left_src)
        except:
            print("Could not load player left image")
            exit(-1)
        try:
            self.image_right = pygame.image.load(Player.right_src)
        except:
            print("Could not load player right image")
            exit(-1)

        new_y = screen.get_rect().bottom - front.get_rect().top

        GameObject.__init__(self, screen, front, 0, new_y, 0, 0, False)

Even without using classes, you can simply have (for example) Player_front_img, Player_right_img and Player_left_img variables holding the image data, without having to read the file every time.

Necrozze commented: That's a really great tip actually, will deffinetly use it! Didn't think of it that way +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Rather than the standard Python time methods, I would recommend using a PyGame Clock object, as the Clock.tick() method is specifically designed for this sort of thing.

I would also take the time out to re-write the code with classes. My own version of this now has a GameObject class and a Player class; I haven't gotten around to the Boss and Bullet classes, yet.

(Is it wrong of me to have completely refactored this program for my own edification?)

chris.stout commented: Clock.tick() is perfect for what's needed here. +2
Necrozze commented: I changed to Clock.tick and now it doesent crash, thanks man +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Oops, that should have been

        DrawASCIICharacter(count, yStart, text[count], CharAttribute);

Apparently, I'm getting confused between languages. This is what happens when you post at 3AM, I guess.

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

Just as an aside, you can remove the #includes for <stdio.h> and <stdlib.h>; you never use <stdio.h>, and <stdlib.h> is the C version of <cstdlib>. Just something I figured I would point out.

Given the number of places where you are writing out a series of characters on a given line in a given color, I would recommend a function like this:

int DrawString(int xStart, int yStart, string text, WORD CharAttribute)
{
    int count;
    int len = text.length();

    for (count = xStart; count < xStart + len; count++)
    {
        DrawASCIICharacter(count, yStart, text.CharAt(count), CharAttribute);
    }

    return count;
}

You will need to #include <string> in order to use this code as it is written. For characters that are normally non-printing, you could use the backslash+numeric code approach:

DrawString(19, 21, "\002 = You", PERSON_COLOR);
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, in that case... actually, you're quite close to it, as it happens. You simply want to have another print line to print a hash before the inner loop, and change the print inside the loop to printing a space:

NUM_STEPS = 6
def main():
    for r in range(NUM_STEPS):
        print ('#',end='')
        for c in range (r):
            print (' ',end='')
        print('#')

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

Test what, our patience? Seriously, even if anyone here were inclined to simply provide code to you - which we are not - you would need to give a lot more detail about what you need.

One of the forum rules states that, when posting for help with a program, you must demonstrate due diligence - you need to show that you have made a good-faith effort to solve the problem yourself, and that you have reached an impasse you can't reslove. In other words, show us your code. If you don't have any code to show us, tell us what you need help in doing. Make an effort first, before asking for a hand-out.

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

One thing that doesn't seem to have been mentioned is that namespaces are less for projects by a single individual, than they are for integrating disparate libraries and projects by different groups of developers. While namespaces are a boon to a single programmer, they are a necessity to developers working with other people's code, where they need to avoid conflicts between programs written without consideration for whether another programmer has used the same class name.

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

Your senior consultant seems to be having a senior moment, I would say. This advice is not only wrong, it is dangerous, because VB6 and Oracle 9i are no longer supported by Microsoft and Oracle, respectively, and neither can even be run on an version of Windows more recent than XP without using virtualization. Microsoft has gone out of their way to make VB6 obsolete. Anyone starting a new commercial project in VB6 in 2013 is out of their mind.

That having been said, VB6 and Visual Basic.Net are completely different languages, with only superficial similarities and the same name tying them together. Moving from an existing VB6 code base to VB.Net is a major headache, which is the main reason the VB6 forum still exists.

Whether any version of VB deserves to exist... well, some people like it, anyway. If I only worked in languages I liked, I'd never get any jobs.

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

OK, and what was your question?

EDIT: The rest of this was incorrect; I had overlooked the fact that fgets() stops at newlines. Please disregard.

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

What everyone is tap-dancing around is that, in order to get a consistent result, you need to synchronize the threads. This means that there would have to be an object which has a synchronized() block associated with it, which acts as a lock on that object - other threads cannot access that object until after the lock is released.

Here I have an example, derived from your code but now quite different, which demonstrates thread synchronization:

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

public class SyncedHelloWorld {

    public static void main(String []args){
        ArrayList<Greeting> g = new ArrayList<Greeting>();

        g.add(new Greeting("Hello"));
        g.add(new Greeting(", "));
        g.add(new Greeting("World!"));
        g.add(new Greeting("\n"));

        Thread[] t = new Thread[Greeting.Count()];

        for (int i = 0; i < Greeting.Count(); i++) {
            t[i] = new Thread(g.get(i));
            t[i].start();
        }
        try {
            for (int i = 0; i < Greeting.Count(); i++) {
                t[i].join();
            }
        }
        catch (InterruptedException e) {
            // do nothing
        }

    }
} 

class Greeting implements Runnable {
    private final String phrase;
    private final int index;
    private static int count = 0;

    // The object position must be an AtomicInteger, as
    // it needs to be mutable. Ordinary Integer objects
    // generate new objects in auto-boxing, and the method 
    // would not have a lock on the new object.
    private static AtomicInteger position = new AtomicInteger(0);    

    public Greeting(String newPhrase) {
        phrase = newPhrase;
        index = count++;
    }

    public static int Count() {
    return count;
    }

    public void run() {
        synchronized(position) {
            for (int i = 0; i < count; i++) {
                // loop …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

When I think of the state of CS education around the world - and yes, especially in India - I am reminded strongly of what Dick Feynman said about Brazilian physics work in the 1950s: that there are a lot of people 'learning' computer programming by rote, without actually understanding the meaning of what they are doing. This isn't to say that there aren't brilliant Indian programmers - I've known several - but they are, for the most part, the one's who went out of their way to learn the subject, which means that despite the public efforts to educate people on the subject, the number of competent programmers is virtually unaffected.

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

Anyone who says that the current generation of programmers is in some way inferior to those of the past, is clearly unfamiliar with the programmers of the past. You must recall that until very recently the vast majority - 90% or more - of programmers were COBOL coders, often with only a few weeks of training before being set loose on the computer world. If you truly think that they were any more inclined to delve deep into the details of the field, you are deluded.

So why do the current coders seem so much worse? It's simple: numbers. The sheer number of newly minted programmers, and the considerable monetary gains to be made by working in this field, mean that the overwhelming majority of newcomers will be people with little actual interest in computing and are looking only for a quick paycheck. This last part has always been true, or at least has been since the early 1970s, but the sheer volume of would-be coders means that the education system in place is being swamped. This is especially true in places like India, Brazil and the former Iron Curtain countries, where the disparity in incomes is even more dramatic and where there have been strong pushes by the national governments to encourage people to enter the field, but little infrastructure added to facilitate them.

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

Oh? What would you need to change it for?

BTW, your operator>>() function may need work; while it will work correctly for a file, it will go into an infinite loop when reading from cin. I would recommend redesigning it to read one line of numbers at a time, and if necessary loop throough the input file explicitly. Also, it will fail silently if the input isn't numeric.

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

Did you solve the problem? If not, what problems are you still having?

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

I take back what I said; there's a much easier solution, one which avoids all this problematic mucking about with the previous nodes: simply swap the values, rather than the nodes themselves.

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

Is there a specific requirement to use the bubblesort algorithm? With a linked list, an insertion sort would generally make more sense.

The main thing you'll want for bubblesort that you don't already have is some kind of swap() function. Since it is a singly-linked list, you'll want to pass it the nodes previous to the ones to be swapped.

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

You would find it much easier to detect many bugs of this sort if you indent the code in a suitable fashion. While it may take some getting used to - it makes the code look like some sort of modernist poetry - it is well worth the trouble. There are even tools available to perform indentation for you, and these often do a better job than you would do by hand.

For example, here is your code as rendered in Allman Style using the AStyle tool:

#include<stdio.h>
#include<conio.h>

char oper[4];
int num[2],*a,*b;
int ans,i;

int main()
{
    clrscr();
    for(i=1; i<=5; i=i+1);
    a=&num[0];
    printf("Num:");
    scanf("%d",a);
    printf("");
    scanf(" %c",&oper[0]);
    {
        {
            if(oper[0]=='+')
            {
                b=&num[1];
                printf("Num:");
                scanf("%d",b);
                ans = *a + *b;
                printf("%d",ans);

            }
            else if(oper[0]=='-')
            {
                b=&num[1];
                printf("Num:");
                scanf("%d",b);
                ans = *a - *b;
                printf("%d",ans);
            }
            else if(oper[0]=='*')
            {
                b=&num[1];
                printf("Num:");
                scanf("%d",b);
                ans = *a * *b;
                printf("%d",ans);
            }
            else if(oper[0]=='/')
            {
                b=&num[1];
                printf("Num:");
                scanf("%d",b);
                ans = *a / *b;
                printf("%d",ans);
            }
            else
                printf("Error");

        }
    }
    getch();
    return 0;
}

Perhaps this will help you see where the problem lies with the for() loop. If not, consider what the semi-colon at the end of the loop conditional means.

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

The immediate cause of the errors are a) the statement typeof(n) in the initialization section of the for loop, and b) the lack of a semi-colon at the end of f *= i. However, this ignores a more serious conceptual error (for which the compiler gives only a warning), in that it assumes that the for() loop will return a value, which is not the case.

What is really happening is that you are making one of the classic C/C++ conceptual errors, namely, confusing macros with functions. While parameterized macros do indeed seem to act like functions under certain circumstances, they are not functions, and treating them as if they were can come back to bite you.

In this case, if you look at the actual code generated by the pre-processor, the statement would become:

int j=for(typeof(i) i=2; i<=i; i++){f *= i};

A few moment's thought should make it clear why this won't work, even aside from the collision of the two i variables.

As an aside, you should never use void as the return value of main(); the correct return type for the main function is int.

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

What is position, and where is it initialized?

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

For the record, I thought you might want to see the version of the program I came up with; you may find it Illuminating fnord as far as the techniques I used for it.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

const int total_categories = 3;
enum CATEGORY {DELUXE, SUV, LUXURY};
const char* category_name[] = {"Deluxe Vehicle", "Sport-Utility Vehicle", "Luxury Car"};
const int category_size[] = {3, 3, 3};

struct Car
{
    char make[16];
    char model[16];
    char year[6];
    int price;
};

const struct Car DELUXE_MODELS[] =
{
    {"Maruti", "Zen", "2011", 4000},
    {"Maruti", "Omni", "2012", 5000},
    {"Volkswagen", "Polo", "2011", 15000}
};

const struct Car SUV_MODELS[] =
{
    {"Tata", "Sumo", "2010", 9000},
    {"Chevrolet", "Tavera", "2009", 12000},
    {"Trax", "Toofan", "2011", 10000}
};

const struct Car LUXURY_MODELS[] =
{
    {"Mercedes", "E350 Sedan", "2012", 9000},
    {"BMW", "640i Convertible", "2012", 12000},
    {"Audi", "A5 Coupe", "2012", 10000}
};

const struct Car* MODEL_CLASSES[] = {DELUXE_MODELS, SUV_MODELS, LUXURY_MODELS};

struct Customer
{
    char name[32];
    int age, daysOfRental;
    char phone_number[16];
    char address[3][32];      /* three lines of 32 chars each */
    struct Car* vehicle;
};

/* function prototypes */
void printBanner();
void getCustomer(struct Customer* customer);
enum CATEGORY getType();
const struct Car* getCar(enum CATEGORY type);
void printReceipt(struct Customer* customer);
void strTrim(char* s);


int main()
{
    struct Customer customer;
    enum CATEGORY type;

    printBanner();
    getCustomer(&customer);
    type = getType();
    customer.vehicle = (struct Car*) getCar(type);
    printReceipt(&customer);

    return 0;
}

void printBanner()
{

    printf("\n CAR RENTAL APPLICATION \n");
    printf("\n ----------------------- \n");
}

void getCustomer(struct Customer* customer)
{
    char ndays[4], age[4];

    printf("\nEnter the number of days you want …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Is this the entire header file? If so, you will need to #include the header for the base class (as well as <windows.h>, to bring in CString) at the beginning of the file. I would also recommend adding include guards around the file, to prevent multiple definition errors.

A minor note on nomenclature: I assume that 'CYoda' is the name of the package in question, right? I don't know if this is feasible, but it may make more sense for you to have a CYoda namespace, rather than having CYoda prepended to each and every class name. That would at least shorten and simplify the naming, while still having the namespace control that th prepends are apparently meant to provide. I realize that this may not be something you have control over (e.g., if it is a requirement of a company style guide), but I thought it should be mentioned.

What are the macros ACCOUNTING_MYLIB_DECL and DECLARE_MESSAGE_MAP () for, anyway? One should always be careful when working with macros of this sort, especially ones which mark up a declaration in non-standard ways.

I should finally mention that, these fora are not like chat or Twitter, where you can and will get immediate responses most of the time. Different people are in different timezones, and not everyone reading these is likely to respond. It can take several hours to get an answer here, and a quick response is often a sign that your question isn't well worded …

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

I suspect that this is because you are tyring to print a standard int value with %ld, the formatting marker for long int. I you need values greater than 2 billion, then you need to declare the variables as long or even long long (depending) as well.

BTW, has this assignment been handed in yet? It's been over a week.

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

As I said earlier, you want to have the per day as a constant, and multiply that by the number of days to get the total.

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

First off, as we've already said before, you really should change void main() to int main() and have it return 0; at the end of the function.

Second, the way you now have it, the prices for all the cars will be the same, and total price will always be 120,000; the price per day will decrease with the number of days. I think what you want is more like:

 printf("\n You have selected TATA SUMO | %ldrs per day \n ie total %ldRs\n",12000, 12000 * nod);