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

> i am wondering which language (java or c#) can create more robust and scalable application
Only to say that choosing one of them doesn't mean you're immediately immune from screwing it up.

A bad design in either language is perfectly capable of turning into a disaster.

Or that your ultimate choice of language(s) should be guided by your detailed requirements and design, and not by some washy "wish-list" containing only two or three things.

Rashakil Fol commented: This. +7
Salem 5,265 Posting Sage

That is unfortunate....

But your description so far is about as useful as phoning up the doc's and saying "I've got a red patch of skin" and expecting an expert diagnosis.
http://www.catb.org/~esr/faqs/smart-questions.html

Show some commands you ACTUALLY tried.

Lightninghawk commented: :) +5
Salem 5,265 Posting Sage

> Please, this is very important to make the chair at the university.
Sure, and what makes you think you deserve it any more than someone who can do this assignment all by themselves?

And if you get there, what makes you think you're up for the job of tackling the next (and more difficult) problem?

#include <std_free_lunch.h>
Error code 0x0BADF00D - file not found

Salem 5,265 Posting Sage

Sure, just press ALT-F4

Salem 5,265 Posting Sage
Rajesh R Subram commented: Neat! +1
Salem 5,265 Posting Sage

You do some reading before trying to get us to do some writing.

Nick Evan commented: It's great how he transform his homework-assignment into a question by just adding a questionmark :) +12
Salem 5,265 Posting Sage

Yeah, right, good for you.

Now complement your copy/paste skills with some reading the forum rules skills.
http://www.daniweb.com/forums/announcement8-2.html

Salem 5,265 Posting Sage

http://www.daniweb.com/forums/thread252440.html
gets me this error message

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 3842759 bytes) in /home/daniweb/httpdocs/forums/includes/class_bbcode.php(172) : eval()'d code on line 150

I'm assuming the OP has pasted a bitmap (or some other stupid thing) into the message, rather than an attachment.

Salem 5,265 Posting Sage

> This is not my homework problem ,i am preparing for one exam in for the position of junior software engineer in one of the company ,
> so i am trying to learn programmimg as much possible,iam just a beginer
Unless this is an absolutely lowest rung of the ladder position, for a student or apprentice, then you're wasting everyone's time.
At the moment (and for many months to come), you're going to need a lot of hand-holding. Which is fine if that is what the company is expecting of you.

But if you're trying to blag some more senior position "on the fly", then you're going to become unstuck in a hurry.

Fact is, these kind of questions are dead easy for people who are capable of doing the job. The problems you will get in the job will be vastly harder and more complex to solve, and it is there that you will realise just how far out of your depth you'll be.

Salem 5,265 Posting Sage

Compression is an algorithm, independent of it's implementation language.

You could implement ZIP in assembler, C or Java (or pretty much anything else) and the end result would be the same.

Or do you have some other metric for "best"?

Salem 5,265 Posting Sage

So why does
vector.c include vector.h
AND
vector.h include vector.c

tux4life commented: Super helpful, as usual :) +6
Salem 5,265 Posting Sage

Unless you can post an actual bit of code we can copy/paste into a compiler, then I'm afraid there isn't much to say.

The problem isn't in the bit you posted, it lies elsewhere.

Salem 5,265 Posting Sage

We only give homework help to those who show effort
http://www.daniweb.com/forums/announcement8-2.html

> write a c++ program to eliminate blank space ,comments, tabs in a given file.
How about starting with a program which simply COPIES the input file to the output file?
Can you manage that?

If you can, then it's a good start, maybe then you can add some tests for say tab characters.

If not, then there is no point us explaining the complicated stuff if you can't deal with the simple stuff. Not that it matters to us, but we really need to know where to pitch the advice.

Salem 5,265 Posting Sage

How about you explain what YOU think the answer is, and wait for us to comment on it.

As opposed to merely dumping the assignment on us and waiting for the answer on a plate.

Salem 5,265 Posting Sage

All the port numbers, and what they're used for.
http://www.iana.org/assignments/port-numbers

nezachem commented: Beaten! +1
Salem 5,265 Posting Sage

> while(scanf("%d %d", &row, &column) != EOF);
Guess what the ; at the end of this line does.

As in while(scanf("%d %d", &row, &column) != EOF) { /*nothing at all here */ }

Salem 5,265 Posting Sage

> When God created the universe 6,000 years ago..
Who's god?
Each mythology has its own creation date, yet oddly enough (no, not really, the dates were invented without evidence), they don't agree with one another. Why not? because the date was yanked out the ass of some ancient mystic and nobody had any knowledge or sense to challenge it.

There are trees which pre-date this particular creation date. I wonder how the explanation of that goes (no, not really, the answer is obviously "goddiditandIllkillanyonewhosaysotherwise").

No doubt some ancient (that is dead) religion had a much earlier creation date. Is that date only false because it lacks enough idiots to jump up and down saying "it's true because I say so"?

Next problem - what colour skin did Adam have?
I mean, with an average generational span of say 30 years (today's figure), that gives only 200 generations to generate the whole of human diversity. Now that's impressive even for evolution!
If they give some "environment" waffle as the answer, kindly point out to them that Blacks (say) in Scandinavian countries do not suddenly become White in the new environment, nor do their children.
Would you "adam and eve it" (A&E)

More on evolution
- old religions die,
- new religions are born,
- some(*) evolve from peaceful origins (allegedly) into a band of …

Salem 5,265 Posting Sage

> why we have an int type when we already have short and long ints
You got it the wrong way round.
C evolved from B and BCPL, where the only data type was "the machine word". This became the int type in C. The short and long got added later (but still available in K&R C).

In archaic C, the default data type was int, so you could just say things like

main ( argc, argv )
char **argv;
{
}

where argc was an int, and the return result of main was also int.

When the ANSI/ISO standards came along, then
short int - at least 16 bits
long int - at least 32 bits
int - at least 16 bits, but ideally should reflect the architecture of the machine.

> because int means either short or long.
No it doesn't. Your experience to date only suggests that int is either short or long.
The standards only specify MINIMUM ranges for each data type. Beyond that, the compiler implementer has quite a lot of freedom to choose.
On some DSP chips, short, int and long are all the same (32 bits).
On common Intel hardware, short and long are different, and int is the same as one of them.
When 64 bit hardware becomes common, short is likely to remain at 16 bits, int at 32 bits and long may move out to 64 …

Salem 5,265 Posting Sage

Create two meaningful variable names, like

int spacesBeforeFirstStar = 11;
int numSpacesBetweenStars = 0;

Then perhaps

for ( rows = 0 ; rows < 5 ; rows++ ) {
  // some stuff
  spacesBeforeFirstStar -= 2;
}

Not meaningless variable names like a and b.

Salem 5,265 Posting Sage

Try learning English!
Try reading the link I posted earlier.
Try reading the intro threads.

One thing guaranteed to piss people off is "leet" or SMS speak on a forum. You've got a full keyboard and plenty of space to write what you mean. This isn't some 160 char limit via SMS.

Aia commented: Do or do not. Try is for those that do not. ;) +8
Salem 5,265 Posting Sage

Lines 42 to 45 need { }

You should always use them, even in the places where they're considered optional. It takes almost no effort to add them (none at all for intelligent IDE's), but the amount of bug hunting they cause by omission can be huge.

Salem 5,265 Posting Sage

1. Create a separate struct for the deque itself.
2. Remove all those global temps - eww!!!
3. Separate the 'create a node' from the 'add it to the deque' functionality. Two simpler functions are much easier to deal with than some do-it-all bloater.

The essence of all this should be something like

struct deque {
  struct node *head;
  struct node *tail;
};

void push_front ( struct deque *q, struct node *n ) {
  if ( q->head == NULL ) {
    q->head = n;
    q->tail = n;
  } else {
    n->next = q->head;
    q->head = n;
  }
}

void push_back ( struct deque *q, struct node *n ) {
  if ( q->head == NULL ) {
    q->head = n;
    q->tail = n;
  } else {
    q->tail->next = n;
    q->tail = n;
  }
}
xavier666 commented: I understood the application of nested structures. Thanks a lot! +1
Salem 5,265 Posting Sage

You start by asking a half-decent question (did you just see Yes, or did you bother to read the link underneath it).

I mean, have you actually "tried" anything at all?

What format is your data? How do you intend to map that to a gray scale?

Which OS are you using? what compiler?

All sorts of information you could clarify to help us to help you.

What we're NOT going to do is write a complete application for you "blind" only for you to say something like
- i found it somewhere else
- that's too complicated
- what does "some trivial statement" do?

etc etc

Salem 5,265 Posting Sage

> when I deal with clipboard, I have to use GlobalAlloc.
Because it tells you to in the manual pages perhaps?

If the API's you're using have special requirements which mean you MUST use GlobalAlloc's special properties, then that is what you must use.

If you're just writing standard C++, then use new.

Salem 5,265 Posting Sage

IMO, it's better to understand the concept from a language point of view, than knowing what ONE single implementation does in ONE specific test case.

Salem 5,265 Posting Sage

Why can't you use STL vectors?

I mean, the problem was solved 5 seconds after you posted.

The STL exists to stop people continually worrying about minutiae, and get on with solving the problem at hand.

If you're somehow worried about performance, then you'd be advised to actually finish the program and then profile it with real-world data. Premature Optimisation Disease (POD) has wasted many a month of programmer effort to save microseconds of run-time. Your chance of guessing where the hot-spots 'a-priori' are close to zero.

To delete the middle from an array, simply loop from [n+1] to the end of the array, and copy to [n].

Salem 5,265 Posting Sage

> Well, i have used this program in visual C++ 6.0.
VC6 is over 10 years old. The world has moved on, and so have the standards for C++.

> And i have n't posted this code without consulting a proper teacher.
Ever hear the adage "those that can, do; those that can't, teach"?
It is our considerable experience which suggests there are a lot of teachers out there who couldn't find their own ass in the dark, nevermind teach C++ (or programming in general) with any degree of competence.

Just because someone who claims to be your teacher has checked the code does NOT make it bug free (Narue trivially proved this to be the case with your array overstep), but your teacher didn't spot that did they?

In the real world (if you hope to program beyond college), your code will be reviewed many many times by lots of people with vastly more experience of programming than either you or your teacher. Mistakes will always be found.

Salem 5,265 Posting Sage

I wonder if in a couple of years, some brain-dead doofus will bump this thread with "plz snd me ur plagiarism detection codez" :D ;) :twisted:

jonsca commented: Priceless! +1
Salem 5,265 Posting Sage

http://www.sgi.com/tech/stl/Deque.html
You need two "push" functions, one for each end of the deque.

> temp3 = (node *)malloc(sizeof(node));
Why are you casting the result of malloc - there is no need to do so in a correct C program.
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1047673478&id=1043284351

Salem 5,265 Posting Sage

> How do I fix that ?
You use the error enumerations in errno.h (like EPERM) rather than magic numbers like 2 and 13

> How do I test the return value of stat to tell if it failed ?

int result = stat(path, &file);
// RTFM to see what value(s) result can take, and act accordingly.
Salem 5,265 Posting Sage

Standard C doesn't allow you to declare variables in the middle of statement blocks.

jephthah commented: that's like almost psychic :icon_eek: +5
Salem 5,265 Posting Sage

Post your code!
Did you initialise i ?

yellowSnow commented: For utter utter patience! +7
Kombat commented: very very patient and helpful!! +1
tux4life commented: You're a patient man Salem. And the help you provide is excellent! +23
Salem 5,265 Posting Sage

Mmm, hidden process, visible .exe - I wonder what's going on here....

Salem 5,265 Posting Sage

> temp=(char**)malloc(rows);
The red is a cast expression, and is unnecessary.

And it is also HORRIFICALLY wrong on the size as well - damn, didn't spot that one earlier.

It should be temp= malloc ( rows * sizeof *rows ); you always have to scale the number of elements you want with the size of each of the elements.

kvprajapati commented: Good point. Excellent advice. +15
Salem 5,265 Posting Sage

Shouldn't the OP be looking for a C++ solution, rather than messing with archaic C-style functions and char arrays?

Dave Sinkula commented: Perhaps. +28
Salem 5,265 Posting Sage

> At the moment I'm considering doing a simulation of hide-and-seek
Well I suppose I could hide my answers to this kind of question all over the forum, and you could write some AI bot to seek them out.

tux4life commented: Nice reply :) +22
Salem 5,265 Posting Sage

So use a counter.

kvprajapati commented: Excellent answer. +16
Salem 5,265 Posting Sage

Seems to me like a case of not using the right tools for the job.

Doing this as a browser plugin would be a snap (by comparison).

Starting where you are, you're basically saying "I need to use gmail to send an email - I know, first thing I'll do is write a really crappy web browser to fetch web pages and do a half-assed job of parsing the HTML and running the embedded scripts".

Sky Diploma commented: The Browser Plugin Idea is exactly what my post missed. :) +9
tux4life commented: Heh, nice spot :) +22
Salem 5,265 Posting Sage

They both run C code.

MosaicFuneral commented: And Google. +6
Salem 5,265 Posting Sage

Doubtful - it won't compile with TurboCrap, and it wasn't posted with code tags.
Does anybody bother to read intro threads?

Salem 5,265 Posting Sage

http://www.daniweb.com/forums/post982800.html#post982800

What you're trying smells like this

Seriously, the only answer you'll get from most people round here in response to "I'm using Turbo C" is UPGRADE!!!!!

yellowSnow commented: Love the answer ... ever so subtle ;-) +6
Salem 5,265 Posting Sage

http://www.codeblocks.org/
http://www.microsoft.com/express/
Both are FREE (except for the time taken to download)
Both WIPE THE FLOOR with the fossil you have.
Both will serve you well when you want to actually USE the OS you're running on.

Have you considered that your 20 year old fossil might not like
- filenames longer than 8 characters
- filenames with spaces
- filenames encoded in unicode
- filenames with characters which are not ASCII
- filenames which are not on a FAT16 file system
And that's just the beginning of all the pain and struggle which awaits.

Salem 5,265 Posting Sage

> Let's say I am using Turbo C compiler in Windows
Sure, why not - if you consider amputation to be a suitable first step to running a marathon.

I shouldn't worry about memory leaks in TurboC. The most it could ever allocate is 640K and that's just no threat to the integrity of your system.

kvprajapati commented: Well said. +14
Salem 5,265 Posting Sage

> file_content = (char *) realloc (file_content, sizeof(char) * file_size);
Is this C or C++?
If it is C, then you don't need the cast.

However, what happens if realloc fails? The problem is, you just trashed your pointer with NULL, thus making it impossible to free a memory leak (if that was your only pointer).

Also, if realloc MOVES the memory block, you've only updated your local copy of the pointer (the one in main still points to the original (and now freed) block).

The whole 3rd parameter is a waste of effort. You may as well have a local pointer, initialise it with malloc and return it.

> file_content[bytes_read-1] = '\0';
What if filesize was in fact zero?
Here you're off into the weeds somewhere, getting bogged down by a segfault no doubt.
Even if the file length is non-zero, you trash the last char of the file.

Also, what if someone tries to load in say a DVD image file - will you handle that well?

What if they call the function with a mode of "w" ?

tux4life commented: Good advice :) +23
Salem 5,265 Posting Sage

That's a nice homework question - what do you think?

William Hemsworth commented: Indeed :) +13
Salem 5,265 Posting Sage
VernonDozier commented: Caught another cross poster. +24
Salem 5,265 Posting Sage

Some additional reading, which Dave's links allude to.
http://www.itis.mn.it/linux/quarta/x86/lock.htm
http://www.dlugosz.com/Repertoire/refman/Classics/atomic_counter_whitepaper.html
http://www.informationdelight.info/encyclopedia/entry/x86_assembly_language

You're not going to be able to do this in simple ANSI C, without getting your fingers grubby with assembler, or getting the OS involved in some way.

Dave Sinkula commented: Danke. +27
Salem 5,265 Posting Sage

> "program to swap two no. using third variable"
A better question would be:
"How to swap my idiot teacher of 1970's assembler tricks with someone who has a clue about programming in the modern world".

majestic0110 commented: lol +4
Salem 5,265 Posting Sage

> How can I combine this one? (TURBO C++)
1. THROW OUT your ancient compiler. It has been obsolete for 20 years. Honestly, this is driving down the information super highway in some clapped out Model-T Ford (did I mention how old it was?). The druids built stonehenge with better technology than this!

Better compilers for your nice modern OS and machine.
http://www.codeblocks.org/
http://www.microsoft.com/express/download/

OK, you may want to finish the current program using the current compiler, but your next step should be to get some decent tools.

> void main()
main returns int - no ifs, buts or maybes.
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044841143&id=1043284376
Just because your compiler accepts it (it accepts a lot of things), that doesn't make it good.

> 56: gotoxy(27,3);textcolor(12);cprintf(" );
See how the rest of your code turned blue?
That's because you're missing a ", and so the compiler things the rest of your code is some mis-mash of strings.

4. Learn to indent code. You've made some kind of effort in a few places, but it really needs to be kept at a much higher standard.
You can find (and prevent) a lot of stupid scope bugs just by making the indentation really good.

> gotoxy(5,2);textcolor(GREEN);
Remove ALL your screen positioning and colouring until the program logic is FINISHED.

When it does what you want, you can then tart it up in about an hours work. Before …

Ancient Dragon commented: Oh! You bothered to read all that mess. +36
tux4life commented: Another beautiful post. And again: in the clean, poetic, Salem-style, with a touch of humor :) +21