Salem 5,265 Posting Sage

Big Picture
Do you have any kind of a design for this assignment?
Because it seems like a large problem, one which isn't going to be solved just by bashing in random code until it works (because it won't).

Think about what your adjacency list class needs to provide
- create
- destroy
- add nodes
- print nodes
- remove nodes
- and so on...

When you have a class, write a simple test for it, something like

int main ( ) {
  myAdjList list;  // should call constructor
  list.add( 1,2 );
  list.add( 3,4 );
  list.print( );  // should see 1,2,3,4
  list.remove( 1 );
  list.print( );  // only 3,4 left
  // destructor called round about now
}

When you have a class which works, then you can use it in anger to solve your assignment, knowing that the basic components are going to work.

Do you need other classes, or just the one and a main() to sequence everything together?
If you need other classes, how are they going to interact with one another.

Draw some diagrams on paper, index cards, post-it notes to remind you of what the overall design of the program is supposed to be.

----- ----- ----- -----
Little Picture

As this appears to be C++, then use C++ I/O.

Eg.

int a, b;
char burnAComma;
while ( cin >> a >> burnAComma >> b ) { …
Salem 5,265 Posting Sage

Check your fingers for typos.
You're doing "ONE-PLUS-PLUS", not "eye-plus-plus"

> • the function is called in the main function as follows:
> nrOccur = nrACGOccur(geneticArray);
And do you do that?
Or do you just call it and ignore the result?

Salem 5,265 Posting Sage

Just print it out in reverse?
Or reverse it "in place" in the string it's stored in, then print it out?

Salem 5,265 Posting Sage

Start at the right, increment it by 1, then scan to the left to see what else can be incremented.

Salem 5,265 Posting Sage

Since that was the reference implementation, meaning it's written for clarity rather than performance, then I guess you're stuck.

IMO, you need to spend more time looking at the code you have, and really trying to understand how it works. If something seems especially complicated, try rewriting it, and then use the test suite to make sure it still works.

This is weeks of work, not come back within a day "is there something simpler".

> Which part shuld be parallelize.
I dunno, it's your idea - what did you have in mind when you started this plan in motion?

My guess would be to look for outer-most for loops which operate on independent blocks of data. If twofish uses one block as part of the seed for the next block, then I don't think this idea will work out. Again, do you know how twofish works for this to even be possible?

Salem 5,265 Posting Sage

Yeah, and yet another post where the noob didn't read ANY of the threads / messages which describe how to post code tags.

Salem 5,265 Posting Sage

If you can't figure out from the first zip file that twofish.c is the algorithm, and tst2fish.c is a test wrapper with all the I/O you could ever need for it, then everything you plan seems beyond you.

happy8899 commented: Good!! +3
Salem 5,265 Posting Sage

Unless it's an array of chars, which if you regard it as a string, is conventionally marked at the end with a \0, then you're stuck.

Given void foo ( char *p ); Then

char a[10];
char *p = malloc( 20 );
foo( a );
foo( p );

As far as foo() is concerned, there's nothing standard to tell what kind of memory it is, or how big that memory is.

Further, this is also valid foo ( &p[5] ); which would almost certainly break any non-standard API which only worked on the result of malloc calls.

freelancelote commented: Thanks. The kind of answer I needed. +1
Salem 5,265 Posting Sage

Pass the size as a parameter. void foo ( char *buff, size_t size ); kinda thing.

Salem 5,265 Posting Sage

Twofish is unpatented, and the source code is uncopyrighted and license-free

Gee, what more do you want?

Nick Evan commented: >"Gee, what more do you want" Haz you got winning lotto numberz lol 1? ;) +10
Salem 5,265 Posting Sage

I still think it might work, if you can figure out a better way of clearing the interrupt other than through the = 0 method you have at the moment.

This is fine when you only have one interrupt, but if you have several, then the approach seems flawed to clear interrupts which haven't been processed.

Another point to remember is interrupt routines should do the least amount of work possible with the fewest resources possible.

Salem 5,265 Posting Sage

Perhaps they've simplified it too much.
Though this question would be better asked on their forum, since they'll know a hell of a lot more about all the details.

Salem 5,265 Posting Sage

Can you show a small program where you call mygetch, and you have to press return twice

Salem 5,265 Posting Sage

What are T0IF and RCIF ?

Imagine an interrupt control register, with flags for various kinds of interrupts.

+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
                          ^   ^
               USART   ---+   |
               TIMER   -------+

Setting both to 0 may be fine, if there is only ever one of them at once.

But to clear RCIF say properly, it would need to be RCIF &= ~0x02; Where ~2 evaluates to 11111101 (in binary), and the & has the effect of preserving all the other bits, and setting the required bit back to zero.

Salem 5,265 Posting Sage

Well the first thing you need to remember is arrays start at 0, not 1.

2. Arrays can be initialised, not assigned, eg

RF_RXTXPAIR_SETTINGS RF_SETTINGS[2] = {
    {0xA8,0x2F,0x37,0x50,0xA0,0x00,0x41,0xF6,
     0x10,0x02,0x80,0x58,0x48,0x44,0x81,0x0A,
     0xFF,0xC0,0x00},
    {0xA8,0x2F,0x37,0x50,0xA8,0x00,0x41,0xF6,
     0x10,0x02,0x80,0x58,0x48,0x44,0x81,0x0A,
     0xFF,0xC0,0x00}
};
Salem 5,265 Posting Sage

Tell me, if the task was to implement it in Java, would you need the same amount of help?

Just do some research (I already gave you one link) and then try and implement it.

Yes, things like
- create list, add node, remove node
would seem like reasonable interfaces to the list class.

Salem 5,265 Posting Sage

There's nothing to stop you from implementing your own "adjacency linked list implementation".

How about "adjacency linked list implementation"

Then make a directed graph based on that, and implement the traversal function.

Salem 5,265 Posting Sage

Or without casts and tricky subscript maths

char (*st2)[133] = new char[st.size()][133];
for(int i = 0; i < st.size(); i++)
  strcpy(st2[i], st[i].c_str());
fn(st2, st.size());
Ancient Dragon commented: great suggestion :) +36
Salem 5,265 Posting Sage

When you hit the segfault, use the "up" command a couple of times so you're looking at this frame
#2 0x000171f8 in Compressor::compress ()
Then list the source code lines so you know exactly where you are.

Then start examining variables (in particular, whatever string you're trying to assign) to see if it's valid.
Maybe your parser returned rubbish.

> The program seems to stop at line 96212. Any ideas?
Use a counting breakpoint at some point where a whole line is read, and make it run for 96211 times. Then start single stepping until you discover something new.

Salem 5,265 Posting Sage

Maybe this linux based tool?
http://home.eunet.no/pnordahl/ntpasswd/bootdisk.html

> the administrator won't let me use illegal software.
So hand the machine over to them, and let them earn their keep for a day or two while you get on with something else.

Salem 5,265 Posting Sage

list in my example was a file, not a command.

> I want to loop through the dir to cat the last 21 lines of each file and put all the output to another file for i in *; do tail -21 $i; done Or begin with for i in *; do echo $i; done just to see what the for loop would use for filenames

Salem 5,265 Posting Sage

string.length()
perhaps?

Guessing you really are using C++ properly, and using std::string, and not say char arrays from C.

Salem 5,265 Posting Sage

First off, which "shell" are you talking about?
There are many varieties (sh, bash, ksh, csh) and syntax varies.

Maybe for i in `cat list`; do tail -21 $i; done

Salem 5,265 Posting Sage

My guess is the host OS isn't DOS at all, but probably something like XP.

The answer is to get one of the many free compilers which are actually compatible with your host OS.

Salem 5,265 Posting Sage

Your array has no size.
My guess, it just trashes memory when you fill the first 10 non-existent slots.

Salem 5,265 Posting Sage

http://www.daniweb.com/forums/announcement8-2.html
So how did you fare with hw1.cpp, hw2.cpp and hw3.cpp ?

Salem 5,265 Posting Sage

Initialise tempcounter for the first time perhaps.

Salem 5,265 Posting Sage

Create a std::vector of std::string with a size of argc.
Then use this
http://www.richelbilderbeek.nl/CppCopy.htm

Just a guess...

Salem 5,265 Posting Sage

Nothing wrong with those functions, only your inability to use them.
If you can't manage memory, then a whole raft of functions become "a problem" for the programmer.

Salem 5,265 Posting Sage

> baseFrom != 2 || baseFrom !=5
So you type in 2
The first one becomes false (good)
The second one (and all the others) remain true (not so good)

You probably want && , not ||

Salem 5,265 Posting Sage

Post some code.

Salem 5,265 Posting Sage

> cmath different in visual c++ and dev c++ ?
The contents which ISO state they should have should be the same, from a logical viewpoint anyway. The actual characters will surely be different.

The problems come in when you use a compiler specific extension in one, which isn't in the other. I don't have the VS compiler to try it to see what it's really complaining about.

Most good compilers have an "ANSI" or "ISO" mode which turns off all the extensions. But even then, it's not a totally foolproof way of making sure your code works on many compilers.

There is a free version of the ISO draft C++ standard on the web somewhere, but I can't seem to find it at the moment. It's definitely worth getting hold of if you want to write portable code.

Salem 5,265 Posting Sage

cmath implements sqrt() for doubles, you pass an int.

Salem 5,265 Posting Sage

Yes, they all give different errors.
But all ISO compilers should spot the same kinds of errors.

Another problem is you're computing sqrt(a) EVERY time around the loop, but the answer will not change from one iteration to the next.

> Does every compiler have different header files?
There's a standard set.
If your code only uses those headers, and is a correct program, then any ISO C++ compiler will be able to compile it.
Having multiple compilers on your machine is a great way of making sure that your code (and your knowledge) is really portable.

The best of the Borland compilers is probably this one
http://www.codegear.com/downloads/free/cppbuilder
Though they've recently started re-using the "Turbo" name for some new offerings as well. I don't know much about them yet.

vidit_X commented: Thanks Salem. +1
Salem 5,265 Posting Sage

You can't deprecate what was never standard to begin with.
void main has always been wrong, despite what many popular books and sloppy compilers say or do

Salem 5,265 Posting Sage

> Is conio.h not ISO C++ standard.
Correct.

> Which funtion to be used in place of clrscr() and getch()?
Such things only matter (to some extent) when you're running from the IDE.
Most programs have neither.
Consider 'dir', which neither clears the screen, nor waits for a key press.

Salem 5,265 Posting Sage

> #include<iostream.h>
This is old. The correct form is #include <iostream>
If you (or your compiler) don't know about namespaces, then it's time you looked into it, or upgraded your compiler. namespaces have been standard issue since 1998, so there's really no excuse any more.

> #include<conio.h>
This is non-standard. If you can write your code without it, do so.

> #include<math.h>
In a namespace enabled compiler, this would be #include <cmath>

> void main()
This is just wrong. main returns an int.

Your prime() function could be more efficient, especially for large numbers.
How many even primes are there?

Salem 5,265 Posting Sage

I don't see why you need to read the whole file in, or store the whole file before writing it out.

while ( <FH> ) {
  chomp;
  my @f = split; # splits $_ at white-space
  print DAT $f[0] . "," . $f[5]-$f[9] . "\n";
}
Salem 5,265 Posting Sage

-W -Wall -ansi -pedantic -O2 Adding these options will spot a lot of things.

Salem 5,265 Posting Sage

I see an = where there should be an ==

What compiler, and what warning level are you at?

Salem 5,265 Posting Sage

Replace
file.txt
with
*.txt

awk reads the file even more implictly than perl does. So implicitly in fact that you don't have to say anything at all.

Salem 5,265 Posting Sage

http://en.wikipedia.org/wiki/Awk

> how do i use it?
About the same as you would perl, except you type 'awk' instead of 'perl'

Along with 'sed' and 'grep', they form a family of text processing utilities which are pretty ubiquitous on any Unix / Linux distribution.

Salem 5,265 Posting Sage

Dead easy in awk (Perl's baby sibling)
Assuming these are comma separated value files, awk -F, '{ print $1 "," $6-$10 }' file.txt

Salem 5,265 Posting Sage

> for (int z = 0; z < 2; z++)
Simply add for (int z = 0; z < 2 && j < i ; z++)

Salem 5,265 Posting Sage

> Data = new string;
Not only does this leak memory, it also loses all your previous input.
You need a way of expanding your array of lines.
Have you considered that std::vector would be ideal for this.

Put the cin.ignore directly after any I/O functions which leave newlines behind.

Salem 5,265 Posting Sage

> while (!myfile.eof())
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046476070&id=1043284351

Use while ( getline(myfile, line) ) Try it with a small text file (say 5 lines) and note the difference.

Salem 5,265 Posting Sage

Function pointers need more ( ) vector<bool(*)(int x)> rules;

Salem 5,265 Posting Sage

Do you have a specific test case?

Are you sure it's not something like
1234567 being displayed as say 1.23456E6 (for example).

Salem 5,265 Posting Sage

Since there is virtually nothing in common (different compiler, different operating systems, different eras), it's very hard to make an objective comparison based solely on one small test of one aspect of one feature of the STL.

It might be an order of magnitude, but it's still the blink of an eye (in human perception terms).

Also, the STL only makes statements about complexity, not performance. If you try your test with 3000 elements and 300,000 elements, you might get a different ratio of performance.

> Do you think that an old compilator can differ a magnitude order from the new one?
Apparently, it can. More inline code, better optimisation and a better allocation strategy - yeah, perhaps it could.


As for your last question, Visual Studio Express is
a) far more up to date
b) far more standard compliant
c) $0 in price.

Salem 5,265 Posting Sage

A couple of things.
1. VC6 is probably 10 years older than your Linux compiler.

2. Have you considered using reserve() to allocate all the space up front, then just subscript your accesses (rather than push_back)