Salem 5,265 Posting Sage

> It reduces the likelihood of accidentally using an assignment statement (a = 1) instead of an equality statement (a == 1)
Or it increases the likelyhood of making a mistake when you have (var1 == var2), and no amount of rearranging the code will save you.

Plus, a lot of people find such code to be highly unreadable.

Further, operand swapping zealots also extend this to the relational operators as well (<, > etc), where there is absolutely no value in doing so. I've seen people introduce BUGS into working code because they made a mess of it.

Most modern compilers will diagnose use of = in an if statement right off the bat, without having to mess with the code at all. And this includes the important edge case where rearranging fails.

http://c-faq.com/style/revtest.html
It's from a time long ago when compilers only had error messages, and blindly generated code so long as it was syntactically correct.
If you're still using such a compiler, consider upgrading.

Salem 5,265 Posting Sage

Protect from who?

If you edit the files, you may end up with a copy in the swap file.

If you delete the file, the data will remain on disk until the space is re-used by the file system.

If you compile the file, then the pre-processor expanded copy of the source might be in the temp directory. Even if it's deleted, problem 2) remains.

Salem 5,265 Posting Sage

> for(int i=1;i<4;i++)
This doesn't initialise ALL the elements.

> bmpHeader.BitsPerPixel=24;
You've said the format is 3 bytes per pixel - so why are you writing 4?

Padding for 4 byte alignment (Could be a value other than zero)

You forgot to take into account this little detail.

Generally, you need to assemble a byte array yourself, then write that out.
Pointing at some struct is generally a bad approach, even when it seems to work.

Salem 5,265 Posting Sage

"(press any key to quit) A
(save before exit?) N
(are you sure?) Y"


For someone wearing one of HG's suggestions...
"127.0.0.2
<-- I live next door to this guy"


One for the ladies :icon_razz:
"Thread Bumps!"

Salem 5,265 Posting Sage

> also to write code fo airline reservation in c...

#include <stdio.h>
#include <geography.h>
#include <volcano.h>
int main ( ) {
  if ( erupting() && wussyEuropeans() ) {
    printf("Sorry, all flights cancelled - come back next week\n" );
  }
  return 0;
}
BestJewSinceJC commented: Haha +5
Salem 5,265 Posting Sage

"Follow me on Twitter
Follow me on Facebook
But follow me wearing this shirt,
and I'll get a restraining order!"

Salem 5,265 Posting Sage

1. "I reported 1000 spam posts and all I got was this lousy t-shirt"

2. http://en.wikipedia.org/wiki/Barcode#UPC
The main logo is the UPC for the T-shirt itself.
Underneath is says "machine-readable and machine-washable".

Just walk past check-outs and see if you can get billed for "1 T-shirt" then complain that you made no such purchase ;)

3. "No user serviceable parts inside - please refer to a qualified technician"

jephthah commented: And i bitched at 1000 Turbo C users. i didnt get nothin. +0
NyQii commented: Good one! +0
Salem 5,265 Posting Sage

> First, do I have to make .ps the file's extension?
Does your OS associate .ps files with a suitable "viewer" that would allow you to see your work drawn (much like a .jpg file would be rendered in an image viewer). It's not strictly necessary to have a .ps extension.

> Second, do I need (or when do I need) the %! command at the beginning of the file?
Always - otherwise it isn't a postscript file.

> And finally, what to do to make the computer execute the program?
IIRC, your average PDF file viewer will read postscript files as well.
Or you can just send it to your postscript compatible printer (though that might be a lot of paper for testing ;) )

Salem 5,265 Posting Sage

Reading the whole line using fgets(), then using either strtok() or sscanf() to parse the line would be my suggestion.

Trying to spot the \n with scanf() would be messy.

Salem 5,265 Posting Sage

It sounded like the OP wanted to write a key-logger.
"It starts with the PC and it saves to a text file (paraphrased)"

Salem 5,265 Posting Sage
1>------ Build started: Project: Manual Stack Implementation, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
[B]1>stack.cpp[/B]
1>Linking...

Have you ever seen it compile stack.cpp ?

If not, you need to add it to the project.

kvprajapati commented: solved. +9
JasonHippy commented: Salem FTW! +2
Salem 5,265 Posting Sage
Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

> Yup, just another dump "project" thread
Sorry jwenting, I meant dumb.

Though "dump" might be more appropriate in years to come, depending one how many lame "me too's" decide to drop by before the thread is finally put out of our misery ;)

jwenting commented: well said :) +13
Salem 5,265 Posting Sage

> cmd_info->infile = malloc(strlen(args) * sizeof(char));
You need strlen(x) + 1 chars to copy a string.

Salem 5,265 Posting Sage

> But howcome this code works perfectly fine in Linux?
Pure dumb luck - that's all.
In another programming scenario, it would be Linux crashing and windows working as expected.

To gain some measure of confidence, you need to use additional tools.
Eg. valgrind ./myprog or gcc -o myprog prog.c -lefence ./myprog Both of these will run your code with additional memory checks, and cause a crash (even better if you're in the debugger at the time - showing you where).

Salem 5,265 Posting Sage

The strange thing is, you only seem capable of generating meaningful sentences when you're mouthing off about how the universe is so unfriendly to you.

The dribble you laughingly call "questions" pale by comparison.

We only give homework help to those who show effort
You got an answer which took as much thought as you put into your question (in other words, bugger all).

Now, if you want to engage on a serious level, then show that you've done some actual work (like citing references and asking specific questions). A good example would be finding two sources which apparently contradict one another.


OK, let's try this again

You:
hello,
Dijkstra's algorithm is it more like greedy search or more like A* or none.
Thanks

Me:
It's most like A*

Do you?
a) feel smug that you got an answer on a plate - spoon-fed style (since you like quoting my cloud), and run off to teacher like some puppy with a new bone.
b) actually get off your lazy ass and check my answer.

It might be the right answer - who knows (well you wouldn't) - but that's just pure dumb luck.

For pith questions like yours, I have been known to make up entirely plausible (yet completely wrong) answers just to see what would happen next.

You see, I have a vested interest in making sure the lazy and the …

tux4life commented: Well said. +8
Salem 5,265 Posting Sage

Your main() needs to declare an ARRAY of int's.

Then have a loop to fill the array.

Reverse it, then print it (another loop)

Salem 5,265 Posting Sage
Ezzaral commented: McDonalds probably won't let you play games either :( +10
Salem 5,265 Posting Sage

There's a queue?

That's mighty generous of you, I was just going with "ignore" ;)

jephthah commented: well, to be honest, it's the "ignore yo' ass" queue.... +7
Salem 5,265 Posting Sage

http://www.daniweb.com/forums/announcement124-2.html

> but i donno much commands in pascal
Better start reading then!

> I need for my homework to make a game
And the rest of the people on your course - what are they doing?

bperiod commented: True... +1
Salem 5,265 Posting Sage

Stop spamming, and claiming that your homework is the most important thing in the universe.
http://www.daniweb.com/forums/thread275902.html

Salem 5,265 Posting Sage
Nick Evan commented: Yes +12
Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

> If 'names' is memory location 3000, are the letters necessarily stored like this?
Yes.

> And "Dean" and "Viky" is hold as two another array of characters in another place in memory.
No.
The OP had a true 2D array, so all the data is contiguous in memory.

Your answer is correct for.
char *names[2] = {"Dean", "Viky"};

Salem 5,265 Posting Sage

> char a_char;
Well you asked for only one char, and that's what you got.

Consider a char array (or better, a std::string ) if you want to store many chars in the same object.

Salem 5,265 Posting Sage

Where is your source code?

Do you have any statements before you start #include'ing files?

Has it worked before, and now it's stopped working?

Which version of the compiler do you have, and which version of the SDK.

Salem 5,265 Posting Sage

http://sourceforge.net/apps/mediawiki/cpwiki/index.php?title=Indentation
Your code is basically unreadable without a lot of effort on our part.
The kind of effort which makes us find something else to do.

Salem 5,265 Posting Sage

You forgot to ask a question.

Note that questions along the lines of "can you write..." are not the sort of questions which will draw a response you'd like.

You also didn't read this.
http://www.daniweb.com/forums/announcement14-2.html

Salem 5,265 Posting Sage

Nearly 30 posts, and you still don't know the rules?
http://www.daniweb.com/forums/announcement8-2.html

http://www.catb.org/~esr/faqs/smart-questions.html
Read that, to see if you can come up with a better question than a vacuous "help please".

Salem 5,265 Posting Sage

The "portable" equivalents would be:

http://pdcurses.sourceforge.net/
http://en.wikipedia.org/wiki/Ncurses

Either provide a fairly fine-grained control over terminal/console type applications.

Salem 5,265 Posting Sage

> If so, how can two programs access the same file at once?
I thought we were talking about streams, not files.

A stream is a conduit between a producer (say your keyboard), and a consumer (your program).

A stream can be redirected, so instead of the producer being a keyboard, it can be a function reading from a file, and stuffing those characters onto the writing end of the stream.

tux4life commented: Nice explanation. +8
Salem 5,265 Posting Sage

> how would I happen to utilize a System.out.printf statement to make three columns with the three headings.
1. Read the manual
2. Make an attempt (fail)
3. Re-read the manual, more carefully this time.
4. Make another attempt (fail)
5. Post small example on the forum showing your attempt and asking a specific question.

We're not a manual reading service, nor an example production service.

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

I found your answer using google.

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

How bad?
http://www.daniweb.com/forums/thread91939.html
2½ years of "me too" 1-posters, all bleating for a project to do.

You'd think they would get the message that the thread is pointless.

Oh well, at least it makes good target practice ▼

jonsca commented: But Salem, they all fell asleep through their entire academic program... ;) Good word choice anyway. +0
Salem 5,265 Posting Sage

Great, another "teacher" who thinks "stupid programming tricks" is a way to teach students.

> other than recursive any other way?
Any other restrictions, before we decide to waste any more time thinking about this pointless question?

Salem 5,265 Posting Sage

You're better off using the actual win32 console API.
http://www.adrianxw.dk/SoftwareSite/Consoles/Consoles4.html

Salem 5,265 Posting Sage

> if (sd1+sd2<sd3||sd2+sd3<sd1||sd1+sd3<sd2);
Watch the birdie!

jephthah commented: quick and painless +7
Salem 5,265 Posting Sage

How about starting with

diff $1 $2 > resultfile.csv

Aia commented: Easy, breezy, beautiful... another fine delivery by the main'ers doomer! +8
Salem 5,265 Posting Sage

> char filename[] = "";
This has no space to store an input - instant buffer overflow and broken program.

Also, consider using fgets() to read each line, then deal with the line in memory.

tux4life commented: Yes. +8
Salem 5,265 Posting Sage

> I hope this is the right place to ask such questions.
The Qt forums might be better.

Forums such as this typically deal with language issues.

When you're deep into some specific oddity of an API, then it's best to check the forums / other support for that API.

iamthwee commented: Well said kiddo. +11
Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

> Yup Right..Can you tell me how it goes?
You already said that in post #1.
Like Walt said, it's all about "use and adapt".

Salem 5,265 Posting Sage

> Looks like your paste has expired.
No it hasn't, the OP just can't paste URLs properly. Delete the trailing ;

> for(int i = 97; i >= 97 && i <= 122; i++)
Assuming you're compiling this as C, then the int declaration inside the for loop is NOT supported.
This is a C++ feature, or a C99 feature.
Since you're using m$, you're never going to get a C99 compiler.

Declare i at the start of the block, old-school style.

thomas_naveen commented: Good catch!! +1
Salem 5,265 Posting Sage

s/urgent/yawning
http://www.daniweb.com/forums/announcement14-2.html

Try a career in management if all you can think of doing is passing the work on to someone else to do.

Salem 5,265 Posting Sage

http://www.cplusplus.com/reference/iostream/ifstream/
Maybe it's something to do with your obsolete compiler, with its obsolete headers.

Compilers which accept "#include <iostream.h>" and void main are really not good anymore.

Ancient Dragon commented: Yup +27
Salem 5,265 Posting Sage

> x=(float**) malloc (T*sizeof(float*));
1. Make sure you're compiling your code with a C compiler (not a C++ compiler). If you're getting warnings about "void* to T*", then you're compiling C++ code.
2. Remove the cast of the return result. It does nothing useful if this really is C code.
3. Make sure you're including stdlib.h. If you fail to include this header, AND you have the cast, then you're potentially hiding a very serious bug.

Use x=malloc (T*sizeof(float*)); or better, since it doesn't refer explicitly to a type x= malloc (T*sizeof(*x)); > memset(x, 0, sizeof(x[0][0])*S*T);
This is wrong for two reasons.
1. The memory you allocated was the result of multiple malloc calls. Thus, the memory is NOT contiguous.
2. http://c-faq.com/malloc/calloc.html
All bits zero does NOT imply a floating point constant of 0.0f
If you really want to initialise this memory properly, then you have to use the obvious nested for loops to initialise each element with 0.0

dr_michali commented: very helpful, thanks! +0