Salem 5,265 Posting Sage

> I know how to add values to an array. I am developing an application
> with RTAI, comedi and Qwt (plotting in realtime).
Oh please tell me you've used a profiler to work out where the real hot spots are, and not just picked random lines of code out based on guesswork.

Dickering about with an array of a few 1000 entries is nothing to the cost of plotting all those millions of pixels in your nice glossy user interface.

You just can't say "draw it" and hope that it takes zero time, because it won't. How you draw it will have a much larger impact on performance than what you're suggesting.

Salem 5,265 Posting Sage

> Half of the world knows CS == C# or Java!
And the other half know that only 1 in 10 people know about binary.

Seriously, if you want lots of $$$ and real job security, then go for Cobol.
http://www.tbray.org/ongoing/When/200x/2004/09/22/Cobol5B
- it's unfashionable, which means not too many young'uns are interested in it.
- it's an old language, so it isn't going to be obsolete any time soon.
- also being an old language, the first wave of practitioners are all soon to retire.
- result -> lots of big business with lots of Cobol to maintain, and very few people to do the work. Figure out the supply/demand implications for yourself.

> and of course I`m gonna put all my focus on that language.just dont whant to regret it!
The language is irrelevant.

Plus you're going to learn several in your programming career anyway, so choosing the first one really doesn't make a difference at all. Chances are that 10 or 20 years later, you won't be using it anyway.

What counts is knowing "HOW" to program. Armed with that knowledge, and a couple of languages picked up along the way, learning language 3 would take about a week.

Salem 5,265 Posting Sage

> I`m a computer science student, I have this problem!:
> I don`t know which programming language I should learn!

http://www.quotationspage.com/quote/788.html
Computer Science is no more about computers than astronomy is about telescopes.

There's a hell of a lot more to it than simply being able to recite a language reference manual.

Salem 5,265 Posting Sage

Your answer seems fine to me.

There are many different ways of solving the problem, but whether any of them are "better" would be a subjective statement IMO.

Salem 5,265 Posting Sage

Well you didn't read this - http://www.daniweb.com/forums/announcement125-3.html

And you didn't say which assembler (nasm,tasm,masm,?asm) you're using. Do you get any error messages perchance?

Nor did you say what you want it to do, nor what it does (or doesn't) do instead.

Salem 5,265 Posting Sage

Well arrays cannot be copied as such.

Consider using something like

struct point {
  int x;
  int y;
};

which is more meaningful than an array of 2 points, and would have proper copy semantics for the vector.

Salem 5,265 Posting Sage

That's what I just told you!
Did you even try it, or just dismiss it?

Salem 5,265 Posting Sage

Try & instead of |

Salem 5,265 Posting Sage

Getting the modulo result is a natural outcome of working out the division.

It's just that when you do x/2, the compiler just looks at a different part of the answer.

Salem 5,265 Posting Sage

> i'w wondering whether there is a difference between fstream and stdio.h
One is C++, the other is C

> i'd need to get every single char and number with getc() and translate i t into whole numbers like 10 am i right ?
It's one way, not the only way.

> is there another function in stdio.h to make things a lot easier and faster ?
fscanf - easy to get going, but hard to make secure.
fgets + strtod / strrol / strtoul - a bit more work, but very safe.

Salem 5,265 Posting Sage

> while(addresses>>link>>name)
Having got to the end of the addresses file once, where do you think you'll start off from with the second word from the keywords file?

Even for a short program, your indentation is mis-leading and needs work.

Salem 5,265 Posting Sage

> If we consider a pointer variable if takes size of 2 bytes
Jeez, how old is your compiler?

Salem 5,265 Posting Sage

Never compare floats using ==
http://c-faq.com/fp/fpequal.html

Salem 5,265 Posting Sage

> since asm is basically ALL about algorithms?
And every other language isn't?
Algorithms and data structures are abstract, they don't need a programming language in order to understand them, study their efficiency, compare with other algorithms etc.

Salem 5,265 Posting Sage

> printf("%3d", transp(i, j, m, n, temp, mat) );
call tansp() before your last pair of loops to print the matrix.

Then just print mat[j] in the loop.

But you might have to rethink your transp() function, and all those parameters you're passing.

Salem 5,265 Posting Sage

Knowing how the internal combustion engine works doesn't necessarily mean you're a better driver.

I've seen many experienced asm programmers turn out the most abominable C you're ever likely to set eyes on.

> that learning assembly is important because it makes you a more efficient coder?
Speaking from personal experience, I'm not thinking about asm when I'm writing C code.
Picking the right algorithm is what really wins big, not worrying about whether a 'for' loop is 5nS quicker than a 'while' loop.
For example, your carefully crafted bubble sort in asm will still suck.

> so that when you move up to C or C++ you take those skills and learn to be more efficient with your code?
Except you have no control over instruction choice. Good compilers' already know this, so you don't have to.

Salem 5,265 Posting Sage

Did you do all that I said?
Like remove the return from the middle of transpose?

Post your new code.

Salem 5,265 Posting Sage

> int transp(int i, int j, int m, int n, int temp, int mat[j]);
C doesn't have variable sized arrays, so this should be int transp(int i, int j, int m, int n, int temp, int mat[MAX_ROW][MAX_COL]); Ditto for the implementation as well.

You might only use the top-left quarter of the array, but that doesn't matter to this function.

> printf("%3d", transp(i, j, m, n, temp, mat[j]));
Would be printf("%3d", transp(i, j, m, n, temp, mat) ); > return (mat[j]);
You're always going to return immediately here.
Perhaps you need to transpose the whole matrix, then print each cell?

Salem 5,265 Posting Sage

> linep = (char *)&line;
Try strcpy() instead.

Salem 5,265 Posting Sage

> so why would one need to know assembly?
Curiosity mostly.

Being able to follow the code the compiler generates, and very rarely writing very small snippets works for me.

Salem 5,265 Posting Sage

So, is the "doesn't work" some kind of rounding error in the result, caused by all those floating point operations?

Or is the "doesn't work" something more serious, like not running at all?

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

http://blogs.msdn.com/oldnewthing/archive/2003/10/22/55388.aspx
Scroll down a couple of pages.

CON was (or still is) the console where you interact with the command interpreter.

Salem 5,265 Posting Sage

You need to pass references to the vectors you are expecting to be updated.

Otherwise, it's just

void foo ( int a ) {
  a = 3;
}
int main ( ) {
  int b = 0;
  foo( b );
  // b still 0 here, not 3
}

Edit: too slow

Salem 5,265 Posting Sage

You have to allocate for each * in turn, starting with the outermost one, and working your way inwards.

Graphics::Graphics()
{
    Width = 10;
    Height = 10;
    TextArray = new char*[Height];
    for ( int h = 0 ; h < Height ; h++ ) {
        TextArray[h] = new char[Width];
    }
    ClearTextArray();
}
Graphics::~Graphics()
{
    for ( int h = 0 ; h < Height ; h++ ) {
        delete [] TextArray[h];
    }
    delete [] TextArray;
    TextArray = NULL;
    Width = 0;
    Height = 0;
}

Note the dtor does the same thing in reverse.

u8sand commented: Solved! tyvm +1
Salem 5,265 Posting Sage

Use CreateProcess()
It's the one native to your OS, and will ultimately give you the most control over what happens.

Use system() if you require no more sophistication than would be provided by a batch file. In other words, very basic "run & forget" approach.

Salem 5,265 Posting Sage

>You are suggesting using the POSIX API's as much as possible
Only for true POSIX systems.

> would it be preferable to change the compiler i have to Cygwin which does
I dunno - that's for you to research.
From what you describe, it might be pushing it too much.

Salem 5,265 Posting Sage

> Would this stop the access to the other pcs please?
I don't think access to individual PCs is the problem.
To allow this, you have to proactively right-click on say a folder and select the "Share..." command, then enter some information. Even after doing that, there may be some setting up of the firewall running on the machine to allow the "share" to be visible outside the machine.

To find out if you have any shares, then press the "windows"-R key combination (like ctrl-c to copy, but with the key next to ctrl :) ). This will bring up the "Run..." dialog, to which you type in "cmd" and press enter.
At the command prompt, enter "net share", and you should see something like this

> net share

Share name   Resource                        Remark

-------------------------------------------------------------------------------
C$           C:\                             Default share
IPC$                                         Remote IPC
ADMIN$       C:\Windows                      Remote Admin
The command completed successfully.

If there's more than that, then questions need asking.

The real problem is that almost all your information appears in clear text on your intranet as it passes from your machine to the router.
Anyone running something like Wireshark would see that, without having to do anything at all to your machine.
The only things which would be presently inaccessible would be say the banking sites you visit which begin with https (as I mentioned earlier).
If he is using wireshark (or similar), then it's pretty sure that he'll know all …

Salem 5,265 Posting Sage

> Why should i put a ; ?
Because it needs it.

However, it might be better placed at the end of InputHandler.h (say at the end of a class declaration), rather than in your C++ code just to make the compiler shut up.

Salem 5,265 Posting Sage

Even without all the passwords, this would be a relatively simple thing to accomplish.

First thing, did you post this from home (in which case, does he already know you're onto something), or did you go to an internet cafe or a library?
Ditto with all the replies that you're going to read.

Also ditto, did you enable the facility which sends you an email every time there is a reply to your thread?
Given the actual title you've chosen, and that you suspect said son can read emails, this would be a bad thing.

> I would be so grateful if someone could please tell me if theres any way I can find this out
Not really. Each machine has a network card, which by it's very nature receives all the information sent by all the machines on your local network. Normally, packets of data which are not addressed to a particular machine are quietly discarded. But it's all too easy to tell the network card to pass the packets to the user instead.

> and additiionally, block him from having this power over the whole family.
This might be harder to achieve, or cost money.

The whole internet is a series of linked machines. For example, between me and google (at the moment), there is

> tracert www.google.com

Tracing route to www.l.google.com [74.125.79.104]
over a maximum of 30 hops:

  1    <1 ms    <1 ms    <1 ms  192.168.0.1
  2     6 …
Salem 5,265 Posting Sage

The short answer is padding and alignment.

> short BM;
> long size_of_file;
To ensure efficient access to size_of_file, the compiler inserts a pair of padding bytes after BM.

The common way to "fix" this is to use something like #pragma pack(1) , but there is no standard way to tell a compiler how to do this (or indeed how well your request for packing the struct will be met).

Also look up "endian-ess"

Unfortunately, the only good long-term answer (which is pretty horrible) is to read/write bytes one at a time, and assign them to the struct in the correct order.

Salem 5,265 Posting Sage

As opposed to say crashing when you do this?

char *s;
string name="ESACPE ";
cout<<snprintf(s,30,name.c_str());

Who knows, dumb luck perhaps.
It's certainly got the potential to crash at any moment.

> name.append("hello '\\' ");
The fact that this made it crash does NOT imply that your previous attempt was bug-free.


Try say
char s[100]; // was char *s

Salem 5,265 Posting Sage

http://en.wikipedia.org/wiki/MD5
MD5 isn't really that safe anymore.

> I will not go into specifics but the users will have access to very sensitive data
Like banking or medical details?
Many countries have legal requirements for compliance (and such like).

> I need to have the best and most secure protection there is for the login system I am creating
That kind of 'best' comes with high price tags.
It's not something you're likely to be able to lash together yourself with a few bits of help from an online forum.

Salem 5,265 Posting Sage

> return time(0)+86400*days;
This is awful, simply awful :(

7.23.2.4 The time function
Synopsis
1 #include <time.h>
time_t time(time_t *timer);
Description
2 The time function determines the current calendar time. The encoding of the value is
unspecified.

Who said time_t must be seconds?

Even then, there are not always 86400 per day either.

Spelled out

time_t now = time(NULL);
struct tm* tm = localtime(&now);
tm->tm_mday += 14;
time_t later = mktime(tm);
Salem 5,265 Posting Sage

You get a tm struct
You then do something like tm->mday += 14;
then do mktime

Salem 5,265 Posting Sage

Read up on localtime() and mktime(), both in time.h

Salem 5,265 Posting Sage

Read this
http://www.daniweb.com/forums/announcement8-3.html

Then allocate some memory for s before trying to write data.

Salem 5,265 Posting Sage

Conceptually, you'll need 4 files.

main.c - the portable part of your application, and #includes port.h
port.h - your abstracted interface to your floppy, with say move_head(int track);
port_win32.c - implements move_head(int track) and the rest of the API, for win32
port_linux.c - implements move_head(int track) and the rest of the API, for linux. If possible, try to do this using the POSIX API as much as possible. It'll save time when moving to other POSIX systems.

When you build a system, you choose (in your project / makefile) the appropriate port_xxx.c for the environment in which you're working.

Do you have specific questions for specific platforms still?

Salem 5,265 Posting Sage

Well the first thing you need to tell us is which OS you're using, and which compiler.

As you've already discovered, this kind of direct access to the hardware is highly specific to your own circumstances.

Salem 5,265 Posting Sage

Either

int foo (void * inputbuffer, int sizeofinputbuffer, unsigned char** outputbuffer)

or

int foo (void * inputbuffer, int sizeofinputbuffer, void* outputbuffer)
and perform the appropriate cast inside the function to get to a proper unsigned char**

Salem 5,265 Posting Sage

Easy, make outputbuffer a void*

Salem 5,265 Posting Sage

> i = *nums++;
Well this does nothing, except to skip the first entry of the array.
You lose i in the following assignment in the for loop.

Salem 5,265 Posting Sage

> Bad idea, you should never return a pointer to allocated dynamic memory
What does malloc do then?

There's nothing inherently wrong with returning a duplicated copy of the string in allocated memory, so long as it's documented that the caller is responsible for calling free at some point.

The only dubious part of it was using the non-standard strdup() to do the copying.

Salem 5,265 Posting Sage

> lets say if the data file is empty and there is nothing to scan i got errors
Well you need to pay attention to the return result of fgets() before you do anything else.

Salem 5,265 Posting Sage

To stop the chicken from crossing the road.

Or perhaps close the window of opportunity to malware when the OS is only partially installed, with network up and NO firewall configured.

Salem 5,265 Posting Sage

Does it also give you warning when you compile?
> puts(restest);
This line should have complained.

> char ***restest = NULL;
Just because your function accepts a char*** means that you should declare your input parameter in the same way.

In this instance, you should have done

char **restest = NULL;
cexplode(&restest, &counter, test, "\\");

You want an expression who's type is char***, not necessarily a variable with that type.

> for (sepcnt = 0; sepcnt < strlen(seperators); sepcnt++)
The string is a constant, so calling strlen() every time is only going to waste time, because it always returns the same result.

> (*array_of_strings)[n] = realloc((*array_of_strings)[n], strlen(pch) + 1);

Each is already NULL, so just call calloc() like you did for this:
> char *parse_this_copy = calloc(sizeof(char), strlen(parse_this) + 1);
Also for parse_this_copy, you need to call free()

Salem 5,265 Posting Sage

Nothing works by editing the file 'in place', even your vi editor.

It's all write the new file, delete the old file, then rename. It's just vi hides those steps from you. On very rare occasions when something crashes, you'll see (and be glad of it) that the old file was preserved and the new file was broken.

Do the same thing in any script you write.

Salem 5,265 Posting Sage

Do you want to delete it because it's line 2, or because it's green?

Read up on the sed command.

For example
sed '2d' file > newfile
or
sed '/green/d' file > newfile

Salem 5,265 Posting Sage

http://curl.haxx.se/ is another library for doing all the donkey work.

Salem 5,265 Posting Sage

Like I said, read the RFCs and be informed.

shaikh_mshariq commented: Provided guidance and reference for what I was looking for. +3