Salem 5,265 Posting Sage

Well searching for "bht scanner" shows that it looks like it is a manufacturer and/or model number for a particular scanner.

My guess is that the .h / .lib file were provided as part of some SDK with the scanner itself.

Perhaps contact the scanner manufacturer to see if they have any updated libraries?

EnderX commented: Thank you for your gracious assistance. +1
Salem 5,265 Posting Sage

> Salem what are you talkin bout that doesn't matter its just code???Gosh
Because with correct indentation, I can figure out what code does about 10x quicker than a horrid unformatted mess like what you've posted.

So on seeing that most people who would help either
- drop your post to the bottom of their "to do" list, and if they run out of time, you lose.
- simply forget about trying to help you as you can't even be bothered with the simple niceties, so you lose again.

But rather than fixing the problem, you instead want to bitch about my attempt to get you to read the rules and improve your post quality.

Nah, forget it, you simply aren't worth the effort anymore.

WolfPack commented: Good in a good tone +7
Sulley's Boo commented: (Y) +3
Aia commented: I must be tone hearing impaired. I don't hear here any tone. +1
Salem 5,265 Posting Sage

> As a good coding practice
That's debatable.
http://c-faq.com/style/revtest.html

It's a special case of a special case.

For example, it only works for ==. Though for some bizarre reason, some people apply it to other ops as well, say turning if ( i < N ) into a very strange looking if ( N > i ) It only works when the left hand side can be an l-value and the right hand side is const. if ( strcmp("hello","world") = 0 ) will draw another kind of error anyway, so there would be nothing to be gained from swapping these over.

What happens when you have to compare two variables for equality?
Oops, the safety net is GONE and you're forced to remember how to do it properly anyway.

To my mind, it wastes the time of people who have to pause to figure out what the code does because it's different from common idioms, and there's always a chance that people will screw it up. I've had personal experience of the operand swappers turning if ( i < N ) into if ( N < i ) because they forgot to swap the operator when they (needlessly) swapped the operands. If all you're going to do is trade one bug for another, you've gotta ask yourself what it is you're getting.

Basically, it is not a free lunch. In attempting to solve one problem, you're just opening the door to …

John A commented: thanks for the info --joeprogrammer +11
Salem 5,265 Posting Sage

If you change the first node (or there is any possibility that you could), you need to return that to the caller.

Eg.
list = appendToList( list, data );

Or
appendToList ( &list, data );

Sure, 99% of the time, the list head doesn't change, but that doesn't help you at all when it really matters.

If you can't change the interface to your list functions, then the interface is broken.

You could also create a DUMMY first node which is always at the head of the list, but that creates problems all over the place as each bit of code has to be aware that a dummy is present.

Salem 5,265 Posting Sage

> You cannot use C to solve this problem.
Of course you can, it just takes an additional library to help you do all the hard stuff.
http://gmplib.org/

Or if you're only interested in a couple of math ops, then you could work out how to do long arithmetic in your own code instead.

Aia commented: Thanks -Aia +1
Salem 5,265 Posting Sage

I'm sure it was worth waiting 2 YEARS for you to show up with an answer :rolleyes:

In the meantime, feel free to swing by the "how to use code tags" readme thread at the top of the forum on how to post code which isn't an unindented mess.

Salem 5,265 Posting Sage

http://www.tek-tips.com/viewthread.cfm?qid=1350973&page=1

> I don't have a debugger since I'm compiling in cygwin
What about gdb ?

$ gcc -g foo.c
$ gdb a.exe
GNU gdb 6.5.50.20060706-cvs (cygwin-special)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-cygwin"...
(gdb) break main
Breakpoint 1 at 0x40107f: file foo.c, line 16.
(gdb) run
Starting program: /home/user/a.exe
Loaded symbols for /cygdrive/c/WINDOWS/system32/ntdll.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/kernel32.dll
Loaded symbols for /usr/bin/cygwin1.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/advapi32.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/rpcrt4.dll

Breakpoint 1, main (argc=1, argv=0x661d90) at foo.c:16
16      {
(gdb) s
17       printf("hello\n");
(gdb)
hello
30       fout = fopen("proj1.dat","w");
(gdb)
31       theta0 = (PI/180.0)*atof(argv[1]);   // initial angle, radians
(gdb) print argv[1]
$1 = 0x0
(gdb) s
     52 [main] a 148 _cygtls::handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
  13223 [main] a 148 open_stackdumpfile: Dumping stack trace to a.exe.stackdump
1600655 [main] a 148 _cygtls::handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
1655972 [main] a 148 _cygtls::handle_exceptions: Error while dumping state (probably corrupted stack)

Program received signal SIGSEGV, Segmentation fault.
0x61016525 in stack_info::walk () from /usr/bin/cygwin1.dll

We know it's going to crash because argv[1] is NULL, and it's about to try and do atof() on it.
The answer is obvious, check and supply the correct command line arguments.


Plus your code isn't …

WolfPack commented: Nice- WoLfPaCk +5
Salem 5,265 Posting Sage

> int array[]={4,3,5,7}
Think about recursion in terms of
4 + all combinations of 3,5,7
3 + all combinations of 4,5,7
..
..

Which becomes in the recursive step
4 + 3 + all combinations of 5,7
4 + 5 + all combinations of 3,7

When you're down to all combinations of just one value, that's when you stop.

~s.o.s~ commented: More power pills than pacman...:D - ~s.o.s~ +15
John A commented: Wow... I never thought of that --joeprogrammer +8
Salem 5,265 Posting Sage

> //A quicker method is to simply use the value as an
Except your other two methods never risk an out of bounds memory access.

> 1. unsigned int arithmatic is faster than signed int.
Where's your evidence?

> 2. registers are registers ! They're simply faster than memory access.
True, but any decent compiler nowadays is far more capable of deciding which variables would be best placed in registers.

> AND it doesn't matter which way you traverse while looping,
Well if you're using it for indexing an array, and your cache is optimised in favour of incremental access, then you lose badly.
I've only ever seen counting backwards to zero save ONE instruction on those machines which specifically have a 'test-and-branch' instruction.

> Another way of optimizing loops is to unroll it:
Or just use the gcc flag -funroll-loops
Better yet, bone up on all the magic which a modern compiler can do, which doesn't involve you mauling the code into an unreadable mess.
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Optimize-Options.html#Optimize-Options

~s.o.s~ commented: Bingo ! More rep** from sos ;) +13
WolfPack commented: Good Advice - WoLfPaCk +5
Salem 5,265 Posting Sage

Make an effort, this isn't www.spoon-fed-programmers.com
http://www.daniweb.com/techtalkforums/announcement8-2.html

Then learn some netiquette
http://www.catb.org/~esr/faqs/smart-questions.html#writewell

The SHOUTING, the colours (it burns it burns), the stupid "leet speek" wannabe writing style, and the overuse of smilies.

John A commented: spoon-fed-programmers.com... I like that! - joeprogrammer +6
Salem 5,265 Posting Sage

> Whats better? C++ or VB?
What's better to a carpenter - a hammer or a screwdriver?

Like the proverb goes, "If the only tool in the toolbox is a hammer, pretty soon all the problems look like nails".

~s.o.s~ commented: So true -- wish people could understand that - ~s.o.s~ +12
Salem 5,265 Posting Sage

From your other post
> Assert failed at line 250 of c:\code\allegro\include\allegro\inline/draw.inl
Open draw.inl in your editor.
Goto line 250.
Read the line which will be something like say ASSERT(x >= 0);

The code expects that expression to be true.
In your program, that expression was false.

Now ask yourself how the condition comes to be false, and how can I make it be true.
Perhaps by initialising variables, or allocating resourses, or ....

Salem 5,265 Posting Sage

Last public draft of C99
Just scroll down to annex J, and they're all listed there.
C89 will have a few less, C++ will have a lot more.

JoBe commented: Thanks Salem +3
Salem 5,265 Posting Sage

> I beg to forgive my eagerness in a fast answer.
No problem :)

Doing the problems is fine (as ~s.o.s~ says), and is a good source of ideas for your own learning.

But the aim is to nudge (then push, then drag) the OP towards the answer based on what they've managed to do so far. Figuring out what they need (not what they want) can be tricky (especially since the OP only posted 5 words). Which is why we like to see code first, it allows us to tune the answer to the OPs level of experience.

Short snippets of code a few lines long explaining how a particular idea might look should be enough to get them going.

Sure, if they're still not getting it after several posts then it's time to roll a bit more code in front of them.

> Very often I ckeck the forum just to see if there's something I can help with
Please do - it's always good to have more contributors.

Salem 5,265 Posting Sage

Cryptography is based on algorithms (and some very heavy mathematical analysis), not choices of implementation language.
http://en.wikipedia.org/wiki/Cryptography

> I mean that can be acctualised using a C program.
Since C is a Turing complete language, if you have an algorithm, then you can express that algorithm in C.

> I think Substitution chiper is good
I look forward to emptying your bank account of all your money - as would any other person with even basic knowledge.

Salem 5,265 Posting Sage

Or save yourself a lot of grief in the long term by downloading a compiler which matches your OS.

Say dev-c++, and if you want graphics then grab the libsdl 'devpak' addition. Then visit www.libsdl.org for examples.

Salem 5,265 Posting Sage

> for(i=0;i<=100;i++)
There are many MANY examples of you accessing outside the bounds of your arrays.

more - db[9][7][0]=6686;
and more - db_init()

Salem 5,265 Posting Sage

Perhaps you didn't read my post.

You're putting 5 characters into an array with only room for 4
Where does the extra one go?

Two guesses
- over the return address from the function
- over another variable
Neither of these is going to make your code nice and functional.

DynamitMsk commented: Very helpful, thank you! +1
Salem 5,265 Posting Sage

> However, since EXIT_SUCCESS is not guaranteed to be 0
No, but whatever it's value it, it will be interpreted as success in the calling environment, even if that value is non-zero.

Even return 0; in your program can be converted into some non-zero success value in the host environment (if you're using a VAX say).

Salem 5,265 Posting Sage

It works because it starts off by doing *p='\0'; to initialise a very small counter to zero.

It's basically using a position in the array as a temporary counter before overwriting it with the modified string.

It does however run into serious problems if the number of characters after the first 's' is more than can be represented in the positive part of a char (say 127 or 255 typically). As soon as that wraps around, then it's bye bye code.

> but to my faculty who had asked the original question..
Is that the same person who told you to use gets() ?

Perhaps you could point out these bugs to your tutor.

Salem 5,265 Posting Sage

> i tried with kbhit() but isnt actually what i was looking for
Did you try

if ( kbhit() ) {
  ch = getch();
}

kbhit() doesn't do any reading, it only tells you if there's something there.

Salem 5,265 Posting Sage

Please don't tell me that's followed by strcpy( cp, tbuff ); If it is, it's a bug.
There is no space for the \0 at the end of the string.

1. In C++, it would be cp = new char[ strlen(tbuff) + 1]; 2. If you're REALLY converting it to C++ (and not just making it compile with C++), then you should be using std::string for all these strings rather than messing about with (and getting it wrong) your own memory allocation.

SpS commented: Right ~~ SunnyPalSingh +3
Salem 5,265 Posting Sage

> typedef int **ppMYARRAY[7]; Thats array of [7] pointers to pointers to int typedef int *(*ppMYARRAY)[7]; pointer to an array of [7] pointers to int

There's a program to help with the complicated ones.
http://packages.debian.org/stable/devel/cdecl

Here's an article on how to read those complex beasties.
http://www.codeproject.com/cpp/complex_declarations.asp

JoBe commented: Thanks for those links Salem +3
~s.o.s~ commented: Impressive, you live upto your reputation Mr. Salem - ~s.o.s~ +7
Salem 5,265 Posting Sage

> The problem is that I can't use
We're not here to play 20 questions to figure out all the "rules" for your assignment. If you keep throwing answers back at us, we'll just get annoyed / bored with you.

> Is it advisable using malloc in c++?
No - malloc doesn't call constructors.

~s.o.s~ commented: Well said Mr.Salem -- ~s.o.s~ +7
Salem 5,265 Posting Sage

This

void func() { 
  static int i = 0; 
  cout << "i = " << ++i << endl; 
}

Is like this

static int i = 0; 
void func() { 
  cout << "i = " << ++i << endl; 
}

With the exception that the scope of the 'i' variable is just the function.

It allows you to create variables local to a function, but which preserve the last known value until the function is called again.

This is very useful for things like

static int initialised = 0;
if ( !initialised ) { doInit(); initialised = 1; }

Or

static int uniqueID;
return uniqueID++;
mattyd commented: TY for your help, Salem. +1
Salem 5,265 Posting Sage

Opening the same file for input and output at the same time is not a good idea.

open for read
read it
close it
do stuff
open for write
write it
close it.

Salem 5,265 Posting Sage

> printf(" user time: %d microseconds\n", sutime);
Go read the manual page for printf conversions again - %d is NOT for doubles.

If you're using gcc as your compiler, then add these flags to the command line gcc -W -Wall prog.c It will then tell you when the printf/scanf format doesn't match the parameters you pass.

Line commented: Thanks for the help! ;o) +1
Salem 5,265 Posting Sage

Something like

( opc >> 11 ) & 0x3f; // 6 bits
opc & 0x3ff;  // 10 bits
andor commented: yup (andor) +4
Salem 5,265 Posting Sage

Does your coke machine do anything more than
- take money
- give can of coke
- give change
?

Take your assignment and put it in your favourite word processor, and reformat it so there is plenty of white space after each sentence with words like "shall", "must", "should" (all the things you need to do basically).

Print that off and start making notes in the gaps about what you understand about the statement. Start categorising things into "input", "process" and "output" say.

Or maybe think about an OO model, say "cans", "money", "keypad" and "display".

Once you've got some idea of the whole picture, you can implement and test it in bits.

Salem 5,265 Posting Sage

> if (operation != 'A' || 'a' || 'S' || There is no compare with a list type function, you need to compare with each one in turn if (operation != 'A' || operation != 'a' || operation != 'S' || Look up the toupper() function operation = toupper(operation); then you would only need half as many comparisons.

Salem 5,265 Posting Sage

Why did you make it static?

It makes ALL the accounts have the same annual interest rate, and that's simply not true in the real world.

You need this just before your main

float SavingsAccount::annualInterestRate = 0;

> using namespace std;
Putting this in a header file is very bad form.
Anyone who includes the file will get the whole namespace whether they like it or not.

hoosier23 commented: very smart +1
Salem 5,265 Posting Sage

> i want to write a program which could convert given temperature and its unit into oher scales
Start with centigrade to centigrade.

Very trivial conversion, but it at least gets you to attempt the first part of actually attempting the "prompt the user and get answers" part of the program.

Then we at least will know which part of the problem you're really stuck on and we can advise accordingly.

Salem 5,265 Posting Sage

See also http://www.daniweb.com/techtalkforums/thread56253.html
> usingnamespace std;
Now I don't know whether this is an endemic problem with your coding, but it should be using namespace std; , that is, there is a space in there.

Now maybe it's you or maybe it's some damn fool code colouring script you're running which is bugged to hell and back. Either way, it's not helpful to have to second guess what the difference is between what you posted and what we see.

Just post your code between

tags, direct from your source code editor. We don't need colouring in a variable width font if the price is mangled code. Keep it nice and simple in a monospaced font.

Salem 5,265 Posting Sage

> But this voltage pattern is not shown in the oscilloscope.
Did you have the right time-base on the scope, compatible with the baud rate of the serial line?

Is it a storage scope, set to capture on the first bit of data? You only get one shot at this, so if you miss it, you won't see it.

You probably have to ground the CTS (Clear To Send) line as well to make the transmitter (your laptop) send the data.

If possible, get two machines wired together (or two serial ports on your single machine) with a NULL-MODEM cable (see link), then watch the lines with your scope. Once you understand what all the signals are doing, then you can 'spoof' a single ended connection which will just absorb data you can see with the scope.

http://www.zytrax.com/tech/layer_1/cables/tech_rs232.htm

Salem 5,265 Posting Sage

> scanf("%s", &retry);
First buffer overflow - retry is a single char, you can't put a string into a single char.
Second problem, calling a function recursively just to implement a while loop is poor form.
Third, you're mixing scanf() with fgets(), which will surely lead to trouble at some point.

Separate the function into two steps
- readInput
- TokeniseInput.

Both will be a lot simpler than what you have at the moment.

Salem 5,265 Posting Sage

Well judging from the colour scheme from your output examples, my guess is you're using some crusty old Turbo C compiler on a nice new XP based system.

Problem number 1
Turbo C knows nothing about long filename, nor filenames with spaces.

It should be paying attention to the COMSPEC environment variable (which should be say ComSpec=C:\WINDOWS\system32\cmd.exe but I guess your compiler sets it to the far inferior command.com (because that's the historic answer for the historic compiler. Command.com didn't know anything about long filenames or space in filenames either.

And this is only one of many possible compatibility problems you'll face with this compiler.

Get a modern 32-bit compiler, one which is far more compatible with your operating system.

Salem 5,265 Posting Sage

> cout << copier;
Why didn't this appear to output anything?

> system(copier);
If the string is garbage in any way, then you'll get that error message.

> string my_copy = "copy" ;
> my_copy += " " + lectut_loca + " " + lectut_name ;
Starting with a string constant is perhaps a bad idea. + is oveloaded for both char * pointer addition (the type of " ") and std::string concatenation (your strings). The compiler might pick the wrong one.
Try

string my_copy = "copy " ;
my_copy += lectut_loca + " " + lectut_name ;
Salem 5,265 Posting Sage

Use the win32 API as referenced in the examples of the cprogramming.com FAQ.

Even if you manage to load ansi.sys, it will only work for true DOS 16-bit applications (which implies some crusty old compiler like turboC).

Anything compiled in win32 will simply ignore it.

You could always use ncurses to get better portability.

Salem 5,265 Posting Sage

> here no matter I use "&" or not it results the same.
Well one or the other is going to produce at least a compiler warning. Choose the one which compiles cleanly.

> why is that?
Sometimes, despite the programmers' best efforts to make a mess of it, it still manages to produce the expected result.
Never confuse "expected results" and "bug free" as meaning the same thing.

Salem 5,265 Posting Sage

> Since this exercise is on STL queue handling, the ranking of candidates found in a ballot should be organized as a queue
The assignment tells you what to use.

So a queue containing pairs of "who" and "how many" would seem to be the thing.

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

> My question is if it is allowed to declare char fields inside a structure
Yes, you can have chars in struct, you can even have char arrays in structs or pointers to chars.

You can even have a char bitfield, but only with fewer bits as already noted.

> we can not use functoins like strcpy
That's because you can't point at a bit-field member.

Why are you using bitfields anyway?

Grunt commented: Precise Wordings [Grunt] +2
Salem 5,265 Posting Sage

> I want function called void ten (void); to go into c particular memory range.
You can, but why would you want to?

Both your operating systems are perfectly capable of running the code at the default address the linker gives to the function. If you move it too far, it might be outside of the address space the OS gives to user programs.

The question is very heavily dependent on the capabilities of your linker. I know "in principle" how to do this with the GNU linker, but only by studying the manual at length.

Manually locating bits of code is something I've only ever had to do for embedded systems where some code has to be placed in FLASH memory for example, and other code is loaded and run from RAM.

Salem 5,265 Posting Sage

In order of preference
strtol() - does conversion and will report numeric overflow / underflow and tell you how much data was processed
sscanf() - like strtol() without the over/under flow
atoi() - pretty useless atoi("0") and atoi("hello") may both return 0

Salem 5,265 Posting Sage

OK, so use that then from now on and don't assume that a particular implementation choice about the inheritance of various objects will be true in other implementations.

My guess is you "got away with" using fstream for cout previously, but this "trick" no longer works on your new compiler.

Which is why you should learn from high quality sources of documentation (like the C++ standard), rather than relying on your reverse engineered observations of a particularly old compiler.

Using multiple compilers even when you don't have to is also a good way of flushing out any assumptions you might be making.

I'm presently using 3 different compilers with pretty strict error checking. It's been a long while since I last used just one compiler for a whole project.

Salem 5,265 Posting Sage

Does your borland compiler also work if you include iostream (only) to get cin and cout ?

Salem 5,265 Posting Sage

Use the debugger and put counting breakpoints on malloc() and free().

For a given file, you're saying that they should be equal.


BTW, if you're thinking that free(tree) frees the whole tree, then you would be wrong. From the symptoms you describe, I don't think you're freeing the whole tree at all.

Does this erode memory like your application does?

for ( i = 0 ; i < 1000000 ; i++ ) {
  char *p = malloc( 100 );
  free( p );
}
Salem 5,265 Posting Sage

> as i have been asked to implement a simple text editor
So a nice simple console editor, with a menu containing a few options
a) insert a line
b) change / edit a line
c) delete a line
d) print some lines
e) load
f) save

Salem 5,265 Posting Sage

for ( i = 0 ; i < 1<<N ; i++ ) Just print out the binary representation of i to N bits of precision.
Easy money.

andor commented: nice (andor) +3
Salem 5,265 Posting Sage

> can u plz help me with de source program... in C
> i have the program which i wrote by myself
So post it (or some meaningful section of it) and ask your C specific question which relates to your code.