Salem 5,265 Posting Sage

If you run the code in the debugger, wait for the assert, then use the stack trace to track back to your code, it should help you figure out the problem.

Salem 5,265 Posting Sage

True or false:
The entire array (not just the first n elements) is sorted.

Salem 5,265 Posting Sage

Gee, 4 posts in 4 minutes.
One wonders how you managed to find the time to read the intro threads.
http://www.daniweb.com/forums/announcement125-2.html


Oh wait, that's right, you DIDN'T!

Salem 5,265 Posting Sage

Which operating system?
Which compiler?
What sort of program - console, GUI, other?

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

You might also consider that if they insist on using gets() that they really don't know C at all. What they're teaching you is a bunch of non-portable rubbish which is only good for the one compiler they know.

It's all very well, but when you come to your next compiler, you could be in for a surprise!.

Salem 5,265 Posting Sage

A hint of geography wouldn't hurt either.
Like "where in the world are you" and "where are you prepared to travel to".

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
Salem 5,265 Posting Sage

Get several sheets of paper, write one letter of a word on each one.
"push" the letters onto a "stack"
Then figure out how to get the letters back in reverse order to print them.

Salem 5,265 Posting Sage

So what's our benefit in solving your homework?

You do know that the whole array is sorted right?

Salem 5,265 Posting Sage

http://clusty.com/search?query=safety+critical+software&sourceid=Mozilla-search
Should take about 10 years to achieve competence.
See you around ;)

Salem 5,265 Posting Sage

You mean the manual page for system() DOESN'T explain it?

Salem 5,265 Posting Sage

strftime

Salem 5,265 Posting Sage

Have you asked pkr.com's tech support?

Salem 5,265 Posting Sage

> i don't know where to start this,
Were you born yesterday, and this is your first programming assignment?

Sure you know how to begin. Look at the first statement and just think about it.
Prompt for input, read some input, print out what was read in.
Surely this was covered on the course, and was the subject of a previous homework (unless you got someone else to do that for you as well, in which case, just drop the course already).

If you can do that much, at least we'd pay some attention to you since you'd actually made an effort.


> and its home work for due tomorrow
How long have you been sitting on the problem?
Your failure to plan ahead isn't our problem.

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

Lemme guess
You're a TurboC user, yet your OS is XP.

Salem 5,265 Posting Sage

http://www.daniweb.com/forums/announcement61-2.html
At least demonstrate that you've
a) searched the web
b) copy/pasted any example code into your c# project.

Salem 5,265 Posting Sage

Ask your 'friend' for help as well.

Salem 5,265 Posting Sage

Lines 32,33 of your code
getData(data, a, counterA);
getData(data, b, counterB);
1. counterA and counterB are both 0, and will remain so after the call. Is this counter a limit or a result?
2. the while eof() thing in the function will ensure a gets all the data, and b none of it
3. the while eof() thing (as neik_e points out) means you go round the loop one extra time.

At the very least, getData() needs to limit the amount of data added to the array with

while ( n < 100 && getline(data,buffer) ) {
}

Oh, and replace the goto in main with another while loop.

Salem 5,265 Posting Sage

The approach used by fgets() is a good way.

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

ls -1rt | tail Newest 10 files in a directory

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

> system("A");
You may be in luck. Some implementations do the right thing with result = system("A"); The POSIX way would be to use fork(), execl() and wait(), something like

if ( fork() == 0 ) {
  execl()  // run A
} else {
  wait() // wait for A, and get the exit status
}

You'll have to read the manual pages for those functions for actual usage.

Salem 5,265 Posting Sage

> i know the algorithm by hand but how do i implement it in C??
That's basically all programming is.
If you know how to do something on paper (the hard part), writing the code for that is pretty easy.

Post your idea and your attempt at the code.

Salem 5,265 Posting Sage

http://www.talklikeapirate.com/piratehome.html

Here be a FAQ for ye all.

Q: What's your favourite data structure?
arrrray's me hearty!

Q: Which virus scanner do you use?
Avast!, and ye be free of the vermin.

Q: What's your favourite syntax?
Arrr, that'll be the main brace to keep your program on a steady course.

Q: What's your favourite programming language?
The language of the C you land-lubber!

Q: What should I do with memory leaks?
Fix them, lest your program become waterlogged and sink to Davy Jones' locker.

Q: How do you count your money?
Aye, tis the pirate way to use octal when counting pieces of eight!

Ezzaral commented: Arrr! Hoist the Jolly Roger, it be the 19th! +12
Salem 5,265 Posting Sage

> if number_of_hours<30,000
Re-read your C++ book or lecture notes for the syntax of an if statement.

And also study how to use more { } to clarify which statements belong to which control structure (if, while, etc).

Salem 5,265 Posting Sage

I think the OP is trying to read the keyboard without blocking on a key being pressed.

It's possible, but it depends on your OS and compiler as to how you do it.

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

> double a[143][2];
You need [3] in the minor dimension.
From looking at your code, you probably need to add 1 to the other as well.

> while(!feof(fp))
Try something like this

char buff[BUFSIZ];
while ( i < 144 && fgets( buff, sizeof buff, fp ) != NULL ) {
  if ( (sscanf(buff,"%lf%*s%lf%*s%lf",&a[i][0],&a[i][1],&a[i][2])) == 3 ) {
    i++;
  }
}

In all but the most trivial of programs, separating "input" from "conversion" is a much easier way to go. You'll get a much more predictable program as a result.


Oh, and as already mentioned, void main is wrong as well. It returns an int.

Salem 5,265 Posting Sage

Perhaps your While not eof should be before your get input.

Salem 5,265 Posting Sage

So what test case(s) does it fail on?
- the first seat?
- the last seat?
- the spill-over when one class is full, and you give the option to book in the other class?

Consider a utility function which searches for a free seat, or returns a flag if no seat can be found.
Eg.

int seat = findFreeSeat( ary, 0, 5 );  // finds seat in first
int seat = findFreeSeat( ary, 5, 10 );  // finds seat in economy
Salem 5,265 Posting Sage

http://www.daniweb.com/forums/announcement114-2.html
http://www.catb.org/~esr/faqs/smart-questions.html#urgent
How about beginning with putting "Gauss-Seidel" into a search engine, and doing some reading.

Salem 5,265 Posting Sage

It's a shame you didn't pay any attention to any of the many places which describe code tags.

But I'm sure someone will be along to fix that at some point, and later still, someone else might get to look at it.

Salem 5,265 Posting Sage

And you initialise it NOWHERE!

Back to you.

Salem 5,265 Posting Sage

> int *Value;
Where does this point?
Answer, nowhere.

You need to allocate some space in your initialise function.

Salem 5,265 Posting Sage

You didn't include stdlib.h, so malloc is incorrectly prototyped.

If this really is a C program, you don't need the cast.

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

Initialise tempcounter for the first time perhaps.

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

Well your while not eof implies that you need to read input inside the loop.
Did you even want a loop here?

Salem 5,265 Posting Sage

> If you want to know what God thinks of money, just look at the scumbags he gives it to.
Indeed, when was the last time you saw a poor and destitute religious leader?

Sure, most of them will claim that it isn't theirs, but they sure bask in the glow of it's close proximity.

Ezzaral commented: Amen. Put your money on the plate please... +12
Salem 5,265 Posting Sage

Sure, you should be able to do something like that.

Salem 5,265 Posting Sage

So it's $1K for the hardware, and $24K for the s/w licences from M$ ;)

Salem 5,265 Posting Sage

http://www.newty.de/fpt/index.html
Pointers to member functions need extra syntax.

> action_index[name].call = (*function);
If you're just storing it (it looks like you're trying to call it), it would be action_index[name].call = function;

Salem 5,265 Posting Sage

There is no "server" or "client", that's why it's called "peer" to "peer". They're both equal to each other.

Listen on a port for anyone who wants to talk to you, and be a "server" to those connections. And attempt to connect to other sites and be a "client".

> So...how can I write the code for it?
The same way that you would for any s/w which has multiple sockets open. Use select() to wait for any activity on any of the open sockets, then deal with any data that arrives, or send any pending data which needs to be sent.

Salem 5,265 Posting Sage

Q1 are you learning C or C++?

> char *temp =(char*)malloc((l+r)*size);
You don't call free(temp) at the end.
Also, if you start at 3 and end at 5, how many slots in the array do you need? Surely it's not 8

You're also modifying l in your code, and you seem to need that later on.

BTW, an identifier of lower-case-L is very hard to read.

Salem 5,265 Posting Sage

Like for example, getting the source code for existing p2p clients?

"p2p" isn't magic. It's just a pair of sockets (usually) and an understanding of the protocol (usually the hard part) of sending and receiving the right information, and knowing what to do with it.