Salem 5,265 Posting Sage

You need VMS
http://www.angelfire.com/mo3/martin0/c/c_intro.html

The return 0 is important. The zero is the exit status of the program, which can be interrogated by the caller. Zero is guaranteed to indicate success in the operating system being used. On UNIX, 0 indicates success, so no change is made. On DEC VAX/VMS, success is indicated by 1 in $SEVERITY, so the zero will be translated to 1.

More here, if you're using that particular compiler...
http://www.ctrl-c.liu.se/conan?key=CRTL~exit%2C_exit&explode=yes&title=VMS+Help&referer=/

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

What a fantastic first post!
Code tags and nicely indented code - top notch stuff.

> The output always reads 0 0 0.
scanf("%s") uses all white space as a delimiter, so no spaces etc will ever appear in your string.

Try fgets( s, sizeof(s), stdin ); instead.

Aia commented: Simple and effective advise. +8
jephthah commented: you can lead a horse to water... +6
Salem 5,265 Posting Sage

C / C++ / M$-mung-ware.

Pick a language and stick to it.

> I tried your code but it only returns 400. I've got that function on a timer.
Well yeah, you would if you tried to \0 terminate a single character.
Instant buffer overrun.

Again, you're posting code without explaining how some of your variables are declared.
What is c[0] all about?

Salem 5,265 Posting Sage

As opposed to the other confusion which would result when trying to explain that ^^ does NOT do short-circuit evaluation like && and || does.

> Let's take this case: 2 == 2 ^ 2 generates a logical operation instead of bitwise operation
Huh?
2^2 is zero.

If you wanted to fake boolean operation, it would be (2!=0) ^ (2!=0) or ( a || b ) && !(a && b) it would still result in the answer zero.

> Should the C++ standard have a xor logical operator? Why ?
Why not NAND, NOR, XNOR etc etc?
There are semi-periodic moans about why ** wasn't implemented as "raise to power of".

It probably reflects the requirements of a few individuals seeking a clean and elegant language which implements the most used stuff well. They stopped adding features when it was useful.

As opposed to a committee designed monstrosity, where every last whim and prejudice is encoded into the language.

Salem 5,265 Posting Sage
johnir commented: Very Helpful +0
Salem 5,265 Posting Sage

Not only does bugger all get done about students posting crappy "do my homework NOW" posts.
http://www.daniweb.com/forums/thread268437.html
and
http://www.daniweb.com/forums/thread265286.html

We can't even discuss ways to challenge their behaviour.
http://www.daniweb.com/forums/thread267094.html

Polite explanation of the rules doesn't work - why would it, they skipped past them the first time around.

Harassment and mockery doesn't work. Trust me, the original title was a lot better :D
The only truly surprising thing about that thread was the muppet came back for another go at trying the same thing.
Mostly they just vanish without a trace if the first reply isn't spoon-fodder.

Maybe we should just ignore them. I wonder if an entrance page full of "homework" posts with 0 replies and 5 days old would help. Such people might just dwell on the two figures long enough to consider their chances better elsewhere.

I suppose spamming the mods with more "report posts" might do for a while. Though between
- the untagged code, even when the students even bother to show effort,
- the lame-asses who can't be bothered to make an effort,
- waves of drive-by spammers of one sort or another
It could be a busy time for them.

It might be a lot easier if we had a "report good post" button ;)
Anything which doesn't get a vote within 24 hours just gets deleted. It would make life …

iamthwee commented: amen +0
Ancient Dragon commented: Yes :) +0
Salem 5,265 Posting Sage
kvprajapati commented: It has to work. +8
Salem 5,265 Posting Sage

> size_t t1 = fread(TGAcompare,1,sizeof(TGAcompare),file);
Although it looks pretty, this isn't the way to read a binary file.

The compiler is free to add padding and alignment to the struct, which the external file format will know nothing about. So what you actually read will be skewed compared to what the file format actually means.

struct header {
    short int type;
    // 2 bytes of padding here
    long int length;
};

If you read this in, believing you're reading 6 bytes, then you're wrong on several counts
- you've read 8 bytes
- 2 bytes of length wound up in the dead space
- the other two bytes of length are in the wrong half of the word
- the remainder of the length contains 2 bytes of the NEXT data element.

Even if you manage to use pragma(pack) or its equivalents, no amount of compiler magic will fix the endian problem if your machine has a different byte order to the file format.

Salem 5,265 Posting Sage

The prototype needs to be void deal (user&, user&, card[]); if you want to modify the details of the user and dealer.

Salem 5,265 Posting Sage

I think the universe would have been much better off if you'd just deleted the post Walt.

Most everyone here would be glad to see someone so lazy to "flame out" of the course they're on. The OP should get their "flame on" down at the local burger joint instead. #include <std_fries.h> // declares do_you_want()

WaltP commented: Good point +11
jephthah commented: i dunno. i've seen more initiative from fry cooks. :P +6
Salem 5,265 Posting Sage

Hemisphere:n Divides the brain into two equally redundant halves.

It might be dual core, but if the lazy.sys device driver is loaded, then not a lot happens for most of the time.

When it does eventually wake up, it's mostly concerned with loading fresh data through the cereal port :)

Salem 5,265 Posting Sage

http://www.daniweb.com/forums/post1157666.html#post1157666
You're presuming that send() and recv() deal with complete messages and are error free.

> printf(recvData);
You will get your ass handed to you on a plate if someone sends you a % character.
http://en.wikipedia.org/wiki/Format_string_attack

Further, recv() does NOT add a \0 to make it a string you can just pass to printf.

Salem 5,265 Posting Sage

The RFCs don't mean squat if you don't know how to write network code to begin with.
http://beej.us/guide/bgnet/

Here's an example of what you need to be doing instead of your "fire and pray" approach.

int mySend ( int socket, std::string &s ) {
  const char *p = s.c_str();
  size_t      len = s.length();
  ssize_t     n;
  while ( len > 0 &&
          (n = send( socket, p, len, 0 )) > 0 ) {
    // successfully sent some (possibly all) of the message
    // if it was partially successful, advance down the string
    // to the bit which didn't get sent, and try again
    len -= n;
    p   += n;
    n = 1;
  }
  if ( n == 0 ) {
    // a send call failed to make any progress through the data
    // or perhaps len itself was 0 to start with.
  }
  if ( n < 0 ) {
    // look at errno to determine what went wrong
    // some values like EAGAIN and EINTR may be worth a 2nd attempt
  }
  return n;
}

Elsewhere, you do

if ( mySend(socket, foo) > 0 ) {
  // more stuff
}

// or
if ( mySend(socket, foo) <= 0 ) {
  // panic and die
}

Now write something similar for recv(), which waits around until it has filled a buffer ending with \r\n (as defined by your RFC).

Salem 5,265 Posting Sage

So just because your luck ran out, you decide that there is a problem with the universe?

Salem 5,265 Posting Sage

> Any other better option available ?
What's your definition of "better"?

> How do I get start with it ?
Read the manual.

> I am not getting how to use these tools ?
Read a tutorial, then read the manual.

Salem 5,265 Posting Sage

I must say that I'm really liking the new prefix the mods are applying to threads wrested from the clutches of the zombies :)

Salem 5,265 Posting Sage

.... you remember the number in Pink Floyd's refrain seemed like quite a large number of TV channels.

The number is a lot larger, but the adjective still fits ;)

ddanbe commented: Yes, I remember. it was the huge amount of 16 channels of... +0
Salem 5,265 Posting Sage

I can't wait for the mention of "Turbo C" that is about to happen....

Aia commented: You made me chuckle. +8
jonsca commented: Can you help me put Wordstar 1.0 on XP? +2
Salem 5,265 Posting Sage

> hope I can get some codes for my project here.
The Architect: Humph. Hope, it is the quintessential human delusion, simultaneously the source of your greatest strength, and your greatest weakness.

Salem 5,265 Posting Sage

> Last edited by krishnakrmsccs; 11 Hours Ago at 06:19. Reason: i need c++ codes for both this algorithm
So slap in some curly braces and semicolons, and you're almost done.

What lazyness!

Salem 5,265 Posting Sage

Lemme guess.

You've found an example for your fossil C compiler (TurboC) that accesses the floppy disk (but it knows nothing about CDs, since it pre-dates them by a few 1000 years).

On the other hand, your brand new machine is so new that floppies are ancient technology (last used by druids), and it only has a CD.

Salem 5,265 Posting Sage

Your array initialiser needs curly braces, not round parentheses.

WaltP commented: Jeez. With this font I couldn't tell... +11
thomas_naveen commented: Gr8 catch !! +1
Salem 5,265 Posting Sage

Interesting, how to be ignored in several places at once.
http://forums.devshed.com/c-programming-42/fseek-and-overwriting-data-683629.html

> p.s. Someone else can describe the common gotchas in your code. I'm a little lazy right now.
About half of this site should cover it ;)
http://sourceforge.net/apps/mediawiki/cpwiki/index.php?title=Main_Page

Salem 5,265 Posting Sage

First off, anyone using gets(s); needs their head examining.

> format(s,sizeof(s),"String is: %s | Integer is: %d | Caracter is: %c",s,d,c); And this differs from the following in what way? snprintf(s,sizeof(s),"String is: %s | Integer is: %d | Caracter is: %c",s,d,c); Further (what, you mean there's more?) format(s,sizeof(s),"String is: %s | Integer is: %d | Caracter is: %c",s,d,c); Using the same buffer for input AND output is real bad mojo (if you want to be technical, it's undefined behaviour).

All you're likely to end up with is a string full of
String is: String is: String is: String is: String is: String is:
or something worse, like wondering where your OS reinstall disks are.

thomas_naveen commented: Nice. +1
Salem 5,265 Posting Sage

See those two 0a 0a ?
Those are TWO newlines.

Use your favourite text editor (or VI), and delete one of the newlines at the end of the file.
No more confusion, the file has one newline, represented by one \n

Geek Joke Moment
VI VI VI - the editor of the beast
:)

Salem 5,265 Posting Sage

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

> Press any key to continue
I suggest ALT-F4

Fbody commented: "I suggest ALT-F4" LOL, Nice :D +1
Salem 5,265 Posting Sage

I have been doing programming in C and C++ for two years. I fetch so many problems regarding to global variable and function prototype as well as return value. Try to do coding less complexity as possible as you can. use function to create a task.

ROFLMAO - 2 years, and you can't do this brain-dead exercise.

My idea is you're just another drive-by recycling rubbish from other forums so you can spam your sig-link.

Salem 5,265 Posting Sage

First off, using a ** pointer is a waste of time in this case.
The size of the minor dimension is a constant, so use it.

> double tree[DIM][DIM];
Can be turned into this VERY EASILY.

double (*tree)[DIM] = malloc( DIM * sizeof(*tree) );

Now here's the real beauty of it all.
You can still call grid( tree ); and not change any other line of code.

When you're done, the whole array is deallocated with free( tree );

Ancient Dragon commented: great idea :) +26
Salem 5,265 Posting Sage

> void mapInit::setMap( unsigned int mapSet ) What does this member function have....

> unsigned int getCell(unsigned int x, unsigned int y) That this 'member' function lacks?

Salem 5,265 Posting Sage

You've reached the end of the road.

Your fossil compiler was obsolete 20 years ago (and at least half a dozen versions of your operating system ago).

C'mon, seriously now - you've got a machine with what - at least 1GB of memory in it.
All that crappy compiler can EVER see is 640K of it - man, why did you bother to spend all that money on a nice new Ferrari, when you just drag it around with some tired old donkey.

Get a proper compiler which is matched to your OS.
http://msdn.microsoft.com/en-gb/express/default.aspx
http://www.codeblocks.org/

jonsca commented: Can you help me get VisiCalc up and running? I can't use Excel. ;) +2
Aia commented: It went through an ear and left through the other without effect. +8
Salem 5,265 Posting Sage

I know you yanks like spelling English words differently, but seriously, it's "Throne", not thrown (which is the past participle of throw).

"Tabloids" and "rumours" - yep, seems about right.

Dave Sinkula commented: Thank you for clarifying "thrown" for me -- I couldn't make sense out of it. :P +0
iamthwee commented: What's rhumour mean? +0
Ancient Dragon commented: Yup -- a spelling misstake +0
Salem 5,265 Posting Sage

> waiting for more =)
Why?

Salem 5,265 Posting Sage

> #include <stdafx.h>
Delete this line,

then do
Project->Settings->Compiler (or pre-processor - depends on which VS you have).

Look for the option that configures "use precompiled headers".
Then turn it OFF.

eddan commented: Fixed my problem, fast and easy. Any other forums haven't even answered after days. Thank you! +0
Salem 5,265 Posting Sage

Give each state a name, not some meaningless number like 0 or 1

typedef enum {
  CH_NORMAL,
  CH_IN_SINGLE_QUOTE,       // found a ', skip until another ', but watch for \'
  CH_IN_DOUBLE_QUOTE,       // found a ", skip until another ", but watch for \"
  CH_IN_OMMENT_START_OR_DIV,// found a /, could be /* or //, but might be just division
  CH_IN_C_COMMENT,          // found /*, now skip to */
  CH_IN_CPP_COMMENT,        // found //, now skip to end of line
} ch_state;

ch_state state = CH_NORMAL;
switch ( state ) {
  case CH_NORMAL:
    if ( ch == '\'' ) state = CH_IN_SINGLE_QUOTE;
    // do other things associated with this state
    break;
  case CH_IN_SINGLE_QUOTE:
    if ( ch == '\'' ) state = CH_NORMAL;
    break;
}

Read about state machines
http://en.wikipedia.org/wiki/Finite_State_Machine

Aia commented: Excellente! +8
Salem 5,265 Posting Sage

> I have doe SQL fro some time now but I have never done blob.
So did you learn what you know by reading the manual, or did you learn it some other way - osmosis perhaps?

> 2. How to create a C++ object to store in blob and get it back? Is ther anything special?
Like a manual?

Salem 5,265 Posting Sage

7.23.2.1 The clock function
Synopsis
1 #include <time.h>
clock_t clock(void);
Description
2 The clock function determines the processor time used.
Returns
3 The clock function returns the implementation’s best approximation to the processor
time used by the program since the beginning of an implementation-defined era related
only to the program invocation. To determine the time in seconds, the value returned by
the clock function should be divided by the value of the macro CLOCKS_PER_SEC. If
the processor time used is not available or its value cannot be represented, the function
returns the value (clock_t)-1.)

Be wary of confusing Accuracy and Precision

The precision of CLOCKS_PER_SEC might be 1uS, but you should not infer that it is accurate to 1uS as well.
It is entirely within the standard that it could just tick once a second with internalClock += 1000000; Or it ticks with the OS scheduler, say internalClock += 20000; // 50Hz tick In the absence of a high resolution clock (say QueryPerformanceCounter), you should do as AD suggested and run the code to be timed in a loop to the point it takes several seconds to run.
You'll get a more accurate average run-time for each iteration of the loop.

But this time will be the "average in a running system", not the ideal best case when nothing else is happening.

Salem 5,265 Posting Sage

> does the standard definition of memcpy varies from system to system ?
No, the standard DEFINITION is that it copies n bytes from source to destination.

The IMPLEMENTATION from one system to another can however vary.
- some systems copy from low addresses to high addresses - starting at src[0] to src[n-1]
- other systems copy from high to low - src[n-1] to src[0]

If the blocks do not overlap, then there isn't a problem.
If the blocks DO overlap, then you risk trashing the data before you've copied it (and no way to guess which way your system does it).

Memmove() exists to always do the right thing.

Dave Sinkula commented: If you ask me, Salem exists to always do the right thing. :P +13
Salem 5,265 Posting Sage

Oh I get it id3tool "name0.mp3" -a "the Album" -r "the Artist" -y "2001" This adds the tags to the dummy file set name=id3tool name0.mp3 | grep Album This is your attempt to read them back again?

Does this command work on it's own? id3tool name0.mp3 | grep Album If so, then the syntax for putting that output into a variable is as follows set name=[B]`[/B]id3tool name0.mp3 | grep Album[B]`[/B] Note the back-ticks!

This is the same, if you're using bash shell. set name=[B]$([/B]id3tool name0.mp3 | grep Album[B])[/B]

Salem 5,265 Posting Sage

> int count0;
Here's the problem, you don't initialise your counters to zero.

Broseph commented: solved thread +0
Salem 5,265 Posting Sage
Nick Evan commented: That's a new bookmark +12
Salem 5,265 Posting Sage

> I was wondering would this be considered a quine?
No.
Reading from a file renders the problem trivial in nearly all languages.

Some real examples
http://www.nyx.net/~gthompso/self_pyth.txt

Salem 5,265 Posting Sage

Post an actual example!

My simple test has no issues.

#include <iostream>
#include <iomanip>
#include <string>
#include <map>
using namespace std;

class CManager {
  enum RespType_en
  {
    eInvalidRes = 0,
    eAuthRes,
    eActivateRes,
    eSetStateRes
  };
  map<RespType_en, string>    m_mRespTags;
  public:
    CManager();
    bool GenerateResponseTagMap();
};

CManager::CManager()
{
  GenerateResponseTagMap();
}

bool CManager::GenerateResponseTagMap()
{
  m_mRespTags[eInvalidRes]        = "InvalidRes";
  m_mRespTags[eAuthRes]           = "AuthRes";
  m_mRespTags[eActivateRes]       = "ActivateRes";
  m_mRespTags[eSetStateRes]       = "SetStateRes";
  return true;
}

int main ( ) {
  CManager  foo;
}


$ g++ foo.cpp
$ valgrind ./a.out 
==3471== Memcheck, a memory error detector.
==3471== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==3471== Using LibVEX rev 1884, a library for dynamic binary translation.
==3471== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==3471== Using valgrind-3.4.1-Debian, a dynamic binary instrumentation framework.
==3471== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==3471== For more details, rerun with: -v
==3471== 
==3471== 
==3471== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 17 from 1)
==3471== malloc/free: in use at exit: 0 bytes in 0 blocks.
==3471== malloc/free: 8 allocs, 8 frees, 187 bytes allocated.
==3471== For counts of detected errors, rerun with: -v
==3471== All heap blocks were freed -- no leaks are possible.
Salem 5,265 Posting Sage

Does reading /dev/sda (for example) read every sector regardless of it's status (as far as the file system bad block map is concerned)?

Bear in mind that modern hard drives may do this stuff transparently for you - silently remapping bad sectors to good sectors.
http://en.wikipedia.org/wiki/S.M.A.R.T..
Whether this actually extends into you being able to read the drives' bad sector map (and even having a go at reading the bad sectors) would need more research.

Salem 5,265 Posting Sage

> Im using Visual C++
...
> Microsoft Visual C# 2008 Express Edition
One of these is a typo surely?

> fopen("Keywords.txt", "r");
In windows explorer, do you have the "helpful" feature of "hide extensions for known file types" turned on?

Actually, it's of no use at all to anyone with any computer skill.
What you'll probably find is your file is really called "keywords.txt.txt".

Salem 5,265 Posting Sage

Are you looking to tie your program to that specific machine, or are you just looking for something which is unique?

If it's the latter, then consider a http://en.wikipedia.org/wiki/Uuid

Salem 5,265 Posting Sage

Perhaps simplify the code.

Say you have a card class.

There are 52 instances of that in a deck.

Then you 'deal' 5 of those instances into another thing called a hand (of 5 cards).

Salem 5,265 Posting Sage

> fileNames = malloc(fileNamesSize * sizeof(char));
One obvious mistake, you're not allocating ENOUGH memory here.
It's an array of char*, not chars.

Use this form for calling malloc - works every time fileNames = malloc( fileNamesSize * sizeof(*fileNames) ); > fileNames[0] = "";
Unless your free loop makes a special case of 0, then blindly trying free( fileNames[0] ); will blow up as well.
It's a completely unnecessary step IMO, just use the first slot for the first filename and the problem goes away.

I'll discuss your realloc mistakes later on.

BestJewSinceJC commented: Very thorough answer. I like the trick. +4
Salem 5,265 Posting Sage

http://en.wikipedia.org/wiki/Digital_signal_processing
But if you're trying to do this yourself, then get comfortable for some serious maths.

> 2. Is comparing the frequency of the wave files still possible?
I've no idea.
But the simpler your answer is, the more likely it is that it will be very specific to only one voice at once (and even then, it might take a lot of training runs).

Salem 5,265 Posting Sage

> Where can I find software and physical parts for making miniature robots
Mmm, lessee now, what's it called again?
http://clusty.com/search?query=robotics+kits&sourceid=Mozilla-search
Hot diggetty, that's right, now I remember....

> Does anybody know where I can get such equipment?
Everybody does, but nobody's sayin a thing

-ve rep welcome; it seems to be the thing when I post STFW responses to null questions.

mrnutty commented: So +rep is not welcome? +4
Salem 5,265 Posting Sage

First, compile with as many warnings as you can.
The compiler will spot things like uninitialised variables, which is a common mistake. Fortunately for you, this seems not to be the case, but still there are issues.

$ g++ -W -Wall -ansi -pedantic -O2 foo.cpp
foo.cpp: In function ‘int main()’:
foo.cpp:132: warning: unused variable ‘COUNT’
foo.cpp: At global scope:
foo.cpp:170: error: extra ‘;’
foo.cpp: In function ‘void Load(ListEle_t (&)[200], Addr_t&, Addr_t&)’:
foo.cpp:204: warning: unused variable ‘Curr’
foo.cpp:205: warning: unused variable ‘Pred’
foo.cpp: At global scope:
foo.cpp:224: error: extra ‘;’
foo.cpp:226: warning: unused parameter ‘Avail’
foo.cpp:255: error: extra ‘;’
foo.cpp:257: warning: unused parameter ‘Avail’
foo.cpp:278: error: extra ‘;’

Second, Use the debugger (Luke)

$ g++ -g foo.cpp
$ gdb ./a.out 
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) run
Starting program: /home/forum/work/a.out 
Program Starting..........
Begining Load..........

Enter the name of the data file to be used:
test.txt
Read Complete.........
Load Complete.........
*** stack smashing detected ***: /home/forum/work/a.out terminated
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)[0xb7e58da8]
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x0)[0xb7e58d60]
/home/forum/work/a.out[0x80499bf]
[0x656e6f]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 08:01 327142     /home/forum/work/a.out
0804a000-0804b000 r--p 00002000 08:01 327142     /home/forum/work/a.out
0804b000-0804c000 rw-p 00003000 08:01 327142     /home/forum/work/a.out
08e6f000-08e90000 rw-p 08e6f000 00:00 0          [heap]
b7d5a000-b7d5b000 rw-p b7d5a000 00:00 0 …