Salem 5,265 Posting Sage

So where is your class?

> Create a class HugeInteger that uses a 40-element array of digits to store
> integers as large as 40 digits each.

class HugeInteger {
  private:
    char myInt[40];
  public:
};

> Provide member functions input, output, add and substract etc etc
Now try ONE of those functions with the above and post your code.

Salem 5,265 Posting Sage

I think the only thing to do at the moment is check the definitions of things like PBDR with the actual hardware.

Another reason for address errors is that there is no memory at the given address.

Another possible reason is that all the segments are at the same address, and it takes several writes (possibly with delays between writes) to the same address to set each digit in turn.

Does the hardware you're using (complete with 7-seg displays) have a specification / data sheet on the web somewhere?

Without specific hardware details (and more than 1 line of code), I can't say much else.

Salem 5,265 Posting Sage

So $3F was stored at 00400586 ?

Did you do a mov.b ?

Perhaps you should also look at your documentation to see which addresses are actually valid for your 7-seg display.

It's not necessarily guaranteed that consecutive segments of your display are mapped to consecutive memory addresses.

Salem 5,265 Posting Sage

> when i declare, has notice : "do'nt enought memory"
So post your attempt then, so it doesn't look like you're just dumping your assignment on us and expecting a polished answer on a plate (it won't happen).

Salem 5,265 Posting Sage

backgroundWorker1_DoWork does
time
Sleep
Work
time

Forground does
time
Work
time

Oh, and you might try removing those pointless for loops which you break out of before they loop.

Salem 5,265 Posting Sage

Lemme get this straight, you're complaining something is 10 seconds slower because it sleeps for 10 seconds?

Salem 5,265 Posting Sage

Are you trying to move a word or a long value to that address?

A number of modern processors do not allow you to store multi-byte values (such as a 32-bit int) on an odd address.

Salem 5,265 Posting Sage

Choose life. Choose a job. Choose a career. Choose a family. Choose a fucking big television, Choose washing machines, cars, compact disc players, and electrical tin openers. Choose good health, low cholesterol and dental insurance. Choose fixed-interest mortgage repayments. Choose a starter home. Choose your friends. Choose leisure wear and matching luggage. Choose a three piece suite on hire purchase in a range of fucking fabrics. Choose DIY and wondering who the fuck you are on a Sunday morning. Choose sitting on that couch watching mind-numbing spirit-crushing game shows, stuffing fucking junk food into your mouth. Choose rotting away at the end of it all, pissing your last in a miserable home, nothing more than an embarrassment to the selfish, fucked-up brats you have spawned to replace yourself. Choose your future. Choose life

Choose dodgy investments from a wunch of bankers.

Choose a fake religion, any one will do.

Choose a president.

Choose to think for yourself rather than letting someone else do it for you.

Salem 5,265 Posting Sage

Pah, a mere lightweight compared to Gv

Dave Sinkula commented: I'd forgotten about that one. :icon_razz: +17
Salem 5,265 Posting Sage

So which bit are you stuck on?
- string to int conversion
- addition
- int to string conversion

And what have you tried?

Salem 5,265 Posting Sage

> This has been posted before. Please use the search function
Are you suggesting they're incapable of finding their own ass in the dark\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b post? ;)
http://www.daniweb.com/forums/thread145077.html

Salem 5,265 Posting Sage

You mean to end up with the equivalent of
str3 db "23",0
?

Do you first know how to copy a string (in C, this is strcpy)
strcat is basically just strcpy called twice, the second starting at the end of the first copy.

Salem 5,265 Posting Sage

> for ( int i = 1; i <= num; i++ )
for ( int i = 1; i <= num; i += 2 )
would generate all the odd numbers for you.

> 8 = 1 + 7
num = i + x right?
So maybe rearrange the expression to put x (the unknown) on one side, and the two known values on the right?

Salem 5,265 Posting Sage

> I've already got rid of the tabs with the tr command so its a lot more cleaner now,
And destroyed any sense of where all the columns are with it no doubt.

If the result is variable width fields, with variable content, which now overlap, then you're stuck.

Fred Flintstone 37 Wilma Pebbles
Barney Rubble 39 Betty Bam Bam

If you'd expanded the tabs with 'expand', and not gotten rid of them with 'tr', then maybe you would have multiple spaces between columns, and some sense of still having a table.

Fred Flintstone     37  Wilma   Pebbles
Barney Rubble       39  Betty   Bam Bam

At least then various utilities can count characters to establish where the fields are.

If you've still got tabs, then extracting individual fields is dead easy.
Eg. awk -F'\t' '{ print $1,$4 }' and save the removal of them until it's absolutely necessary for display purposes say. Even then, you don't mess about with your original data to do it.

Salem 5,265 Posting Sage

> The first part of program is to square the input value (input = r3)
What about r2?

Salem 5,265 Posting Sage

Are you meant to use %c?
Because %s will do the whole thing in one call.

Salem 5,265 Posting Sage

Whole bunch of //!! comments

#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <errno.h>
#include <dirent.h>
#include <sys/types.h>
#include <cstring>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
#include <pthread.h>

using namespace std;
#define MAX_THREAD 65535
void *scanipport (void *arg);
void *ping (void *arg);

//!! typedef (here) is unnecessary
typedef
struct info  {
    string  ips;
    int     startport;       //start port
    int     endport;         //end port
} scout;

void *ping (void *arg)
{
    scout *p = (scout *) arg;
    int i =0;
    static string bohica;   //!! again, static in a thread - see below
    bohica = p[i].ips;
    cout << "131.204.36.xxx subnet" << endl;
    int please = system (("ping " + bohica+" -c 3 -W .0005 -w .0005").c_str());
}

void *scanipport (void *arg)
{
    int     sd;                 //socket descriptor
    int     start;              //start port
    int     end;                //end port
    int     rval;               //socket descriptor for connect
    char    responce[1024];     //to receive data
    char   *message="shell";    //data to send
    struct hostent *hostaddr;   //To be used for IPaddress
    struct sockaddr_in servaddr;//socket structure
    static string bohica;       
    //!! why static?  Especially since you only have ONE OF THEM
    //!! across all the threads.
    int     port;
    const char* host;
    int     s = 0;

    scout *p = (scout *) arg;
    bohica = p[s].ips;
    start = p[s].startport;
    end   = p[s].endport;
    host = bohica.c_str();  //!! host = p[s].ips.c_str(); would save confusion with bohica
    port = start;

    sd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); //created the tcp socket
    if (sd == -1)
    { …
Salem 5,265 Posting Sage

Or just do a difftime() between now and next Saturday @00:14, then call Sleep() for that many seconds.

One calculation, one call to Sleep().
5 lines of code, and it's sorted.

Ancient Dragon commented: great idea -- lot simplier than my suggestion +36
Salem 5,265 Posting Sage

What are you planning to do with the input, when you've finished reading it?

Salem 5,265 Posting Sage

http://clusty.com/search?input-form=clusty-simple&v%3Asources=webplus&query=automated+software+test

The more challenging aspects are:
- how to manage interaction
- how to deal with programs which exit with some kind of exception
- how to deal with programs which refuse to exit.

What is the form of the result?
- return status - easy
- output to a file - harder. Do things like "Program started at hh:mm:ss" count as a meaningful difference?
- output to a GUI on screen - tricky.

Salem 5,265 Posting Sage

> better way...
Still two problems
- what happens at EOF
- the loop can exit with i == SIZE, which means your \0 is out of bounds.

Salem 5,265 Posting Sage

> printf("len = %d\n", strlen(string)); // len = 0
Nope, read my first post again.
string isn't initialised, so your length is junk.
If you get zero, that just makes you lucky.

The rest is getting better though.

Salem 5,265 Posting Sage

> for (i=0; i < strlen(string); i++)
You're lucky this works at all.
string starts off uninitialised, so who knows what strlen() on it will return.

Salem 5,265 Posting Sage

> gives correct output so its correct...
Circular reasoning.
"correct output" just makes you lucky, not good.

> But if it seems that using fflush(stdin) in this required program doesn't make anything wrong
Only the requirement to use a specific compiler.
Like I said, your career will outstrip the lifetime of any single compiler.

If you want to learn a bunch of cheap tricks which "work for me", then go ahead, knock yourself out. But if you post it here as your "best advice", then expect people to crawl all over it and point out the problems with it.

In a 100 line program, you're going to get away with it.

In a 100,000+ line program, every time I've seen something of this scale ported to a new compiler, it's always a disaster area. All manner of sloppy "works for me" attitude all of a sudden generates errors by the boat-load. And even when you've got past all the compilation errors, there's another wave of far harder to find run-time problems just waiting to make a mess of your day.

> But for a small & simple program your writing a flush function(which may make code complex unnecessarily/tedious)
How is a function called "myflush", with ahamed's code in post #3 a vast burden?
It's 2 simple lines, and a function call, and your code is golden.

WaltP commented: Absolutely! +15
Salem 5,265 Posting Sage

> if (argc > 1 )
Still doesn't do much for the safety of argv[2] and [3].

> Ok first like I said I am new to C++
Then try it without threads first. There's a whole bunch of mistakes in there that I'm not even going to explain to you.
First understand exactly how a single threaded solution works.

And you're STILL running off the end of an array which is supposed to be limited by user input.

Salem 5,265 Posting Sage

You're like some pharoah, clueless as to just how big the job is, just waking up one day and deciding "I need a pyramid".

More maths, since you seem incapable of grasping something simple like multiplication and division.

5 months = 150 days => 40 pages per day.

Low estimate of a single page = 2000 characters / 300 words.
Low estimate for day (40 pages) = 80,000 characters / 12,000 words.

Bearing in mind that there are only 86,400 seconds in a day, you need to be a hell of a lot quicker than 1 keystroke per second. A pedestrian 20wpm is a solid 10 hour day.

This is sustained average rate, EVERY SINGLE DAY. There will be days when nothing happens, or where you have a rethink (or the party last night was rather good). Which means the burst rate to keep your average is going to have to be off the scale.

A professional copy typist who can manage 100 wpm, and who doesn't have to think about what is being written could do it. But you're neither a professional typist, nor are you simply copying things. 40 pages/day of useful information – not a chance.


IMO, 60 pages is all what you describe is worth. It might make it into the low hundreds perhaps, but many 1000's is hopeless (and pointless).

Salem 5,265 Posting Sage

> bohica = argv[1];
Your log shows NO command line parameters, not 3 like you assume here.
Always check argc before looking at argv

> for (int kt=0; kt<256; kt++)
Woah, first you ignore the input, now you assume a specific number.

Salem 5,265 Posting Sage

Consider using a struct, like

typedef struct {
    char word[20];
    int  numDefs;
    char defs[10][30];
} definitions;

Then you could have something like definitions dictionary[100]; The raw input code would be something like

for ( w = 0 ; w < 100 ; w++ ) {
  // read a word into dictionary[w].word
  for ( d = 0 ; d < 10 ; d++ ) {
    // read a description into dictionary[w].defs[d]
    // increment dictionary[w].numDefs
    // provide a means of early escape from the loop, say a blank line
  }
}

Though you'd probably want to make it so the user only has to add one word / definition at once, and offer editing features.

Salem 5,265 Posting Sage

> check your compiler's documentation and see if you can use it, then, bare in mind that this code is not 100% portable
a) how is the noob supposed to know what is portable, and what isn't. Half the questions here are basically RTFM or STFW questions, so they've already demonstrated that isn't an option.
b) there's no reason to make an unportable solution when a perfectly valid portable one exists.

It's not just the code which needs to be portable, it's also that grey mush between your ears as well. If you think learning a bunch of implementation-specific hacks is hard, try unlearning them when you change compiler (which you will, many times, if you persue a career in programming).

Writing portable answers here means you:
a) don't have to care what compiler they're using,
b) don't have to write disclaimers all over your posts saying "works with the foo compiler" (not that that ever happens, even when it should).

Otherwise, years later, someone bumps the thread with some barely literate "hey, i tried ur cde n it dn wek".

Salem 5,265 Posting Sage

> Well I tried putting your stuff in a standalone program and it works without any difficulties.
Yeah, tests like that pretty much nail the "it's a bug elsewhere" argument.

Salem 5,265 Posting Sage

6000 pages @ 1 page per day ~= 16.5 years.
Planning anything else afterwards, say the world's longest beard perhaps?

Now if you're doing some proper old-time research (and coming up with genuine new ideas, which is what a PhD ought to be), it might take weeks to come up with a single page of useful material.

But if you're planning on copy/pasting whatever google search results, it's doable.
But it would be the ultimate Write Once Read Never tome IMO.

The index would be so large that it would need it's own index ;)

William Hemsworth commented: heh x] +4
Salem 5,265 Posting Sage

Rest seems fine.

Salem 5,265 Posting Sage

There's an environment variable called PATH which tells cmd.exe where to look.
If the program is in a directory not on the PATH, then you need to specify the full path, say
D:\path\to\prog.exe

Salem 5,265 Posting Sage

The same means this:
Unhandled exception at 0x0002cb80 in Lab4_2008.exe: 0xC0000005: Access violation reading location 0x0002cb80.

But did you do as I suggest, put a breakpoint on mmRes = ::timeGetDevCaps( &timecaps, sizeof(TIMECAPS) ); then step over it?

It that works, then the problem is somewhere else.

Salem 5,265 Posting Sage

I think it's just this.
http://msdn.microsoft.com/en-us/library/ms713416.aspx

But the execution address and the read address being the same seems kinda odd to me.

If that really is the case, then the code took a flying jump off a cliff (typically, following an uninitialised function pointer). The "stack" at that point is pretty much meaningless, so I wouldn't put too much store in that.

Putting a breakpoint at the call, then trying "step over" would give more concrete information as to whether this was the cause, or merely the last bit of salvageable stack from the disaster which follows.

Salem 5,265 Posting Sage

> For that you just use fflush(stdin) after each input line.
Just plain wrong I'm afraid.
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1052863818&id=1043284351

Salem 5,265 Posting Sage

http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046476070&id=1043284351
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1049157810&id=1043284351
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044841143&id=1043284376

Then decide whether you're compiling C or C++, rather than just whatever happens to compile as you think of it.

Also replace the 'goto' with a suitable while loop.

Oh, and also learn about code indentation.
http://en.wikipedia.org/wiki/Indent_style

Salem 5,265 Posting Sage

Which compiler allows the nonsense "unsigned long double" as a declaration?

Alex Edwards commented: XD +4
Salem 5,265 Posting Sage
#include<iostream>
using namespace std;

int main()
{
    int highFive = someRandomGarbage, initialise it!;
    int x = 1;
    int lowFive = someRandomGarbage, initialise it!;

    while ( x < 7)
    {
        x = highFive  Missing ;

        while (highFive > 0)
        {    
            cout << "high five:" << highFive << endl;
            Perhaps some input here?
            Well something needs to get you out of the loop
        }
        printf("give a low five"./n)
        Stick with cout in C++, drop the printf, it's wrong

        return 0;
        Not so much a while, as a once!
    }
} Missing

Some annotations for you to ponder on your code listing.

Salem 5,265 Posting Sage

> I don't really see the point in initializing this variable in the switch
How can you say that when you can't see the rest of the code?

If that variable is used only in that case of that switch statement, then Narue's answer is spot on.

Salem 5,265 Posting Sage

And your question is what?

Salem 5,265 Posting Sage

> I do not have monitor instead I use the DVI port of the video card to connect to the TV.
I would suggest you get (or borrow) a real monitor and plug it into the real monitor port of the video card.

It would seem to me that your secondary video output needs to be re-configured in the BIOS settings (which you lost) before you'll see output on your secondary display.

Salem 5,265 Posting Sage

Did you test it?

Salem 5,265 Posting Sage

An array of days perhaps?
For each day in a range, add the average to the totalFruitsPerDay array entry which corresponds to that date.

Salem 5,265 Posting Sage

'ls' and 'tail'

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

Run the code in the debugger, and catch one to examine it in more detail.

Possible causes
- the string you're copying from isn't "wide" at all, but only looks wide because of dubious casting.
- the string has no \0, because you either forgot, or didn't leave room for one.
- the string is really really long and it fails because of some "guess" by the code that it may be a runaway string.

Salem 5,265 Posting Sage

http://msdn.microsoft.com/en-us/library/y0tzt8e0(VS.80).aspx
My guess is you remove #define _AFXDLL since you're creating an executable (it has a main) and not a DLL.

But if you click the link, and then look at the real cause of the #error, and tell us that as well, we might get further.

Salem 5,265 Posting Sage

> if('\n')
What's this supposed to do?

> node[(data[j]-1)+num*i].pPtr_word=&node[...
> pPtr->pPtr_word=NULL;
This won't even compile.

> count=count++;
Just count++;
But since count seems uninitialised at this point, who knows.

The code is missing half the { } it needs to make it make sense.

And the total lack of indentation makes the rest of it impossible to follow.

On the plus side, you did seem to manage to use code tags on the first attempt, which is a rare achievement in itself.

Salem 5,265 Posting Sage

If it moves, and is smaller, you get a smaller copy.

But (and this is a biggie, because it's a bug in your code), you do this.

p = realloc( p, some_size );
// do stuff upto some_size
p = realloc( p, some_smaller_size );  
// BADNESS
// do stuff with memory past some_smaller_size

Now, if it doesn't move when the size shrinks, you could well get lucky and still see your old data. But your code is broken.
Some time later, making the memory smaller also moves it, and then you're in a completely new place reading garbage.