Bored, are we?
By displaying the picture file do you mean
- Displaying the textual name of the file on the screen?
- Displaying the graphical image in the file on the screen?
Bored, are we?
By displaying the picture file do you mean
make sure you set the timer1.interval property to something relatively low, like 200 milliseconds.
To start and stop a timer, just set the timer1.enabled property to true or false.
123456789
Hmm, OK, you're forgiven. Sounds like you have a lot of tests at once?
You have a very non-obvious error: the default copy constructor is in use.
Make sure that GetSingleton() returns a pointer to type Singleton.
Hope this helps.
Are you saying that it takes 10 seconds for each digit? Or for each change in numbers?
If the latter, make sure you set the timer1.interval property to something relatively low, like 200 milliseconds.
If the former, you'll get a better response by loading all the images once, then just changing the image displayed. You can also avoid some repetition by creatively using some arrays.
For example:
type
TfrmPetrolDisplay = class( TForm )
private
f_images: array[ 1..3 ] of tImage;
f_digits: array[ 0..9 ] of tBitmap;
...
end;
...
procedure TfrmPetrolDisplay.FormCreate( sender: tObject );
var cntr: integer;
begin
// Initialize our "easy access" images array
f_images[ 1 ] := Img1;
f_images[ 2 ] := Img2;
f_images[ 3 ] := Img3;
// Load all bitmaps from file or resource or wherever you keep them
// (this example loads from file)
for cntr := 0 to 9 do begin
f_digits[ cntr ] := tBitmap.create;
f_digits[ cntr ].loadFromFile( intToStr( cntr ) +'.bmp' )
end
end;
...
procedure TfrmPetrolDisplay.FormDestroy( sender: tObject );
var cntr: integer;
begin
// clean up our digits images
for cntr := 0 to 9 do f_digits[ cntr ].free
end;
...
procedure TfrmPetrolDisplay.Timer1Timer( sender: tObject );
var
cntr: integer;
LitresStr: string;
begin
Litres := Litres +1;
// Convert number of liters to a 3-digit number
LitresStr := intToStr( Litres );
LitresStr := stringOfChar( '0', 3 -length( LitresStr ) ) +LitresStr;
// Set each of the displayed digit images
for cntr := 1 to 3 do
f_images[ cntr ].picture.bitmap.assign( …
MSDN is a scary place to navigate. Google often makes it easier. Just type "msdn copyfile" and hit "I feel lucky" and you'll usually go right to the source.
The result is a complete explanation and prototype for the function you are interested in.
Hope this helps.
Snot and bile, eh? Well, you just earned yourself a spot on my ignore list.
Before I go, though, a little advice: as you've missed several points.
C++ FAQ-Lite (on destructors and exceptions).
MSDN blog (clean-up functions can't fail because...)
Some googled examples of why throwing exceptions in clean-up code is bad:
Karsten Wagner's blog
Don't Commit Errorcide by Paul Kimmel
Admittedly, this is an issue which has people on both sides of the aisle, but in my opinion at least, cleanup should almost never get in the way. Enough people agree with me that there is a programming paradigm that emphasizes this fact: RAII.
No OS that I know of will tell you that you are not allowed to close a file.
Hope this helps.
The STL file close functions don't throw exceptions. They will set the fail bit if pending output could not be written before closing, but that's all.
The general rule is that file close functions should not throw exceptions...
LOTRJ, I just typed that in. THere are bound to be some small mistakes. You are expected to use it to get started in finding the information you need to do this yourself.
The function is sndPlaySound
(with a lowercase S at the beginning).
And yes, the std::string needs to be passed as a const char *: hfound = FindResource( NULL, [B]resname.c_str()[/B], "WAVE" );
Hope this helps. Use the Google if you feel stuck, and if that fails come here. I'm not being rude or cruel --this is a skill you absolutely must possess in order to learn to program. (Just like with Blender, you expect people to try a few things before throwing questions at the human dictionaries...)
More often than not I test code that I post here, but I don't plan to build an entire application with resource file just to do something you can... Make sense?
(I am at the limit of my knowledge about using the windows sound subsystem.)
I recommend you find some good references on the net about the things you want to do.
Here's a start:
C++ stuff
simple and uncluttered: http://www.cppreference.com/
complete and detailed: http://www.cplusplus.com/
Windows Waveform Audio http://msdn2.microsoft.com/en-us/library/aa910189.aspx
Windows Multimedia Reference http://technet.microsoft.com/en-us/library/ms712699(VS.85).aspx
Hope this helps.
[EDIT] Ah, you must have found your answers.
Just include <windows.h>
I think that should get you everything you need.
No need to cuss at me... :-O
There is something wrong with your windows.h includes. The LoadResource function, according to Microsoft, looks like this: HGLOBAL LoadResource( HMODULE, HRSRC );
In my MinGW (GCC) winbase.h file (which is included by windows.h), that is properly listed as: WINBASEAPI HGLOBAL WINAPI LoadResource(HINSTANCE,HRSRC);
Whatever library you are using that says LoadResource takes or returns pointers of any kind, or takes more or less than two arguments, is wrong.
Make sure you have the correct windows headers.
[EDIT] Woot! 1000th post!
I'm sorry, but you got too much of a bone from that last one.
Method 1:
Get yourself a large piece of paper and a couple pennies. Draw yourself two lists, like 4 7 9 23 -2 14 5
6 5 1 0
place the pennies at the head of each list (one above the four and one above the six). The pennies represent your current index into each list.
Now, looking only at the numbers at the pennies, copy those numbers over into a new list, properly sorted.
Method 2:
Check out the merge-sort algorithm.
Hope this helps.
O-notation always covers the worst-case scenario. I don't think you can get an algorithm better than O(n*n) without sorting.
However, it is always possible to reduce the number of comparisons done. Things that work along the lines of a hash-table would probably work best.
AFAIK.
After some googling, I think your build path may have spaces in it. Make sure it doesn't.
Let me know if that fixes it.
Well, no one else is responding so here's my take. Mind you, I've never tried to do this so I can't claim I know everything there is to know about it.
Windows is pretty particular about not permitting the exe file to be modified while the program is running. So, there are three options I can see (the first two are common, and I don't know if the last would really work or not [for those same technical restrictions]).
Hope this helps.
Well, I've just glanced over your code, so I'll run through the most obvious errors first, and give some useful suggestions, and see if that doesn't help.
1. main returns int.
2. You have not very well documented your code. In fact, it took me until I was reading through the aMpyC() and addTo() functions that I finally 'got it' that eArray is a bignum.
Also, your variable names need some work. I will not address that below, but poorly named variables are an indication of a nebulous understanding of what they do. This is what you are struggling with mostly at the moment-- making the structure match what you think it ought to be doing.
So, with that in mind, lets fix the very first part with some proper documentation.
// eArray
//
// The eArray class represents an unsigned
// integer of arbitrary precision. You can
// set it to a number, add a number to it,
// multiply it by a number, and print its value.
//
class eArray {
...
};
3. You are forcibly using too much memory. Each element of data[] should represent only one digit of the number. (Yes it is possible to use all the bits in each element, but it is tricky and you are trying to do it the simple way anyway, so we'll stick with that.)
Also, you will likely save yourself some space if you use bytes instead of machine …
Example of how to convert a string to (upper/lower/title)-case.
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
class lowercase {
public:
int operator () ( int c ) { return tolower( c ); }
};
std::string toTitle( std::string s ) {
std::string result( s );
if (!s.empty()) {
std::transform(
s.begin()+1,
s.end(),
result.begin()+1,
lowercase()
);
result[ 0 ] = toupper( s[ 0 ] );
}
return result;
}
int main() {
using namespace std;
string s;
cout << "Please enter a string> ";
getline( cin, s );
cout << toTitle( s ) << endl;
return EXIT_SUCCESS;
}
Enjoy!
Heh heh heh... I do stuff like that all the time... :twisted:
Please fix those get()s to read()s though...
Maybe you are just paying the price for using ifstream.get()? Is there a byte with the value 10 in your data file?
(You should be using ifstream.read().)
Let me know if that fixes it... (ATM I don't think it will...)
You changed every instance of &buffer
to buffer
in both of the routines posted above?
If you have, I don't know where the problem is. My quick glance says they look alright to me. Unless you are reading or writing too many bytes for your buffer or integer types somewhere...
Does your custom vertex structure have any pointers in it?
Oh, yeah, almost forgot. Initialize your constructors this way:
class Movie {
private:
string director,title,genre;
public:
Movie(): director(""), title(""), genre("") {}
};
int main(){
Movie a;
}
Have fun!
A little googling answered it. The reason is that myclass foo();
is a function prototype...
but myclass foo( 12 );
is not...
duh
/me slaps head :$
Hope this helps. :)
It is because you are not calling the default constructor.
Use Movie a;
(without parentheses).
I can't remember the reason for this, but I've read it somewhere. Give me a minute to look it up.
The assembly line only points to where the IP was when the error was identified. (So it doesn't help.)
In any case, the problem is that unsigned char buffer[ n ];
creates a variable (buffer) which is, by itself, a pointer to a list of bytes. The number of bytes in the list is known to the compiler, but otherwise the array definition is just like saying:
1. reserve n bytes on the stack
2. create a variable unsigned char *buffer;
3. let buffer point to the first byte just reserved on the stack
Hence, the problem occurs when you say: memcpy_s(&i_CountInds, sizeof(long), [B]&buffer[/B], sizeof(long));
The types of the desired parameters are:
pointer to bytes, int, pointer to bytes, int.
The types of the arguments you give it are:
pointer to bytes, int, pointer to pointer, int.
So, the first time you read something you are changing the address in 'buffer' to point to some other, random position in memory. The next time you try to access the buffer you get an access violation --meaning that you tried to access memory that doesn't belong to you.
Remember, buffer
by itself is a pointer. You can dereference it with *buffer
or buffer[ 0 ]
but without the * or [] it is just another pointer variable.
So, to fix your code, use memcpy_s(&i_CountInds, sizeof(long), [B]buffer[/B], sizeof(long));
Hope this helps.
Yes, don't feel bad. This trips up a lot of people.
The << and >> are always for doing text output. If you know any C they are comparable to the printf() and scanf() functions. In other words, they always convert numbers to/from their string representations.
So, like vijayan121 said, you'll have to go to a raw output function: f_DataFile.write( reinterpret_cast<const char *>( &i_verts ), sizeof( i_verts ) );
Good luck.
[EDIT]
That said, I think you are mixing integers and arrays.
x and y should each be an integer, not an array.
However, like vmanes said, knowing nothing about your eArray class I could be entirely wrong...
[/EDIT]
This is actually easier than you think in C++
#include <iostream>
#include <sstream>
...
while (getline( eyetrack, line )) {
if (line.empty()) continue;
stringstream ss( line );
{ string val;
getline( ss, val, ',' );
stringstream( val ) >> x;
}
{ string val;
getline( ss, val );
stringstream( val ) >> y;
}
}
This snippit is, of course, without any error checking other than skipping blank lines...
Exactly. However, making one a reference and one a value doesn't help. If I were to say:
double x, y;
x = foo( y );
How would the complier choose between double foo( double );
and double foo( double & );
?
More infuriatingly, even if I were to say:
double x;
x = foo( 12.0 );
the compiler would give me a hard time about choosing one. (The literal could be promoted to a temporary!)
This is because resolving between overloaded functions is not academic. The C++ standard is notoriously wishy-washy about this stuff (though, that can't really be helped due to implicit conversions and type promotions). The basic way it is done is to choose based on the least-bad worst-choice.
If you want more reading, here're a couple short, easy-to-read articles I just googled that touch on this very problem, including trying to differentiate based on value or reference.
C++ Week 20: Function Overload Resolution
ACCU: Overload Resolution
(I learned some cool stuff reading them myself.)
Hope this helps.
I think that you need to increase your stack size.
You can do it from the Options -> Compiler -> Memory Sizes menu or use the $M directive at the top of your code.
{$M 32768, 655360} { Twice the default stack size, default heap size }
program fooey;
begin
writeln( 'Hello world!' )
end.
Let me know if this helps.
I don't know. What does your opinion of QuickBasic languages [1] have to do with the OP's question?
[1] which are, QuickBasic, QBasic, and FreeBasic, the latest being proof that the QBasic language tree is not dead (even if it ought to be).
PS. Perhaps we ought to turn this into an "I hate BASIC" thread"? :-/
OK, JRM, you've completely lost me. The link you gave gives the exact definition of an overloaded function that I've been giving throughout this whole thread.
Calling the same function with different variables is not overloading.
There must be a difference in type or number of static arguments to overload more than one function to have the same name.
Have I misunderstood what you are trying to say?
Sorry again... :$
Nice catch on the type of input.
Wait, I thought you said this was to prepare for an exam?
I didn't post that code just to give you an answer. Your professor will recognize if you turn in homework with an unusually brilliant answer (brilliance comes with time --something new programmers haven't had a lot of).
Make sure you understand exactly what is going on and can justify why it does what it does if you do use it (or some variation of it). Otherwise your professor may mark you as having failed to learn something...
The important point (the non-brilliant, required part) is in the loop: each time through the loop two elements (one from each list) are added to the new list, thus creating the alternating effect. So long as at least one list has elements it continues.
As an exercise, see if you can modify it so that it terminates when either list exhausts (that is, so that it discards extra elements of the longer list). You'll have to change one thing (to know when to stop), and add one thing (to make sure the new list is terminated with a nil pointer).
Hope this helps.
Look, I didn't mean it caustically, OK? Consider the circumstances yourself: you are requiring the OP to do finding to answer your own questions about the material. Particularly when just a short moment of googling it yourself would have given you the information you needed. It is not the OP's fault if you are unfamiliar with the terminology. If you can't find his words listed anywhere, then it may be safe to ask for clarification. That's all.
Yes, I know that. But that doesn't overload the function, it just adds another parameter.
double total( double captial, double adjust, double rate ) {
return capital +adjust +(capital *rate);
}
What? Did you read the original question?
Yes, and I read every other post here also, including yours.
He did indicate that he wanted to navigate bi-directionally in his list.
No, at no point did he indicate that. His original post at no time indicates that his list has 'back' pointers, nor did he ever say he needed to walk it backwards.
In fact, in post #4 he did say
I only know how to move forward in a list and not go backwards.
which is as close as he ever got to indicating anything about the directionality of his list. You go re-read stuff.
I was reading between the lines that he was 'supposed' to extend a list because
Oh, that's your problem. Requirements engineers don't like programmers who like to "read between the lines".
because - let's face it - you'd only implement linked-lists in C++ as an exercise. Any commercial dev would use STL.
Bull. You are aware, perhaps, that the STL 'list' container is specifically a linked list? Oh, and that some others may be also? You may not care what I think of the laughable "one-size-fits-all" argument, but you should at least find out what people who are recognized experts think (That is but one example). Any commercial dev would use the most appropriate tool for the task, whether or not that involves the STL.
Olam's code fragment did mention 'tail' ergo to remove the last item in …
Hmm, you've actually got a bit of work ahead of you. I see two possibilites:
1.
Have two pictures of a keyboard: one with all keys up and another with all keys down.
Display the picture of the keyboard with all keys up and whenever you get a keydown or keyup event (WM_KEYDOWN, etc.) copy the appropriate part of the appropriate picture to the image you are displaying to the user.
2.
Using a form designer, drop a tpanel or tbutton or something for each key on the keyboard and arrange them to look like a keyboard. Attach their key up and key down event handlers to something that alters their appearance appropriately.
Good luck.
You've got the right idea. Use some other string functions to help better:
for each book do begin
if AnsiStrPos( AnsiUpperCase( book[i].title ), AnsiUpperCase( title1 ) ) <> 0 then ...
end;
Geez, DimaYasny, if you have no clue what he's talking about at least Google it, instead of wasting his time with "what?".
Whenever you want to "zip" two lists (whether linked-lists or not) you'll need to keep a finger in each source list, and alternately copy elements to the new list. Something like
function zip( ls1, ls2: student ): student;
// Zips two lists.
// Either ls1 or ls2 may be nil.
// If both are nil, the result will also be nil.
// The new list is allocated with new().
var
results: student; // the head of the new list
current: student; // the current elt of the new list
function copy( elt: student ): student;
// Adds a new node to the new list
// and copies the specified elt to the new node.
// Returns the node following elt.
begin
if current = nil
then begin
// create the first node in the new list
current := new( student );
results := current
end
else begin
// add a node to the new list
current^.next := new( student );
current := current^.next
end;
// copy elt to the new node
current^ := elt^;
// return the next elt
copy := elt^.next
end;
begin
// no new nodes yet
results := nil;
current := nil;
// So long as either source list has elements
// we'll copy them to the new list, alternating
// if possible
while (ls1 <> nil) or (ls2 <> nil) do …
Don't tell someone to add complexity. There is no need to add more pointers. People delete the last element of singly-linked lists all the time.
Olams, assuming your list really is a singly-linked list, to delete the last node you will need to start at the head node and traverse the list until the next node is the last node. Then you can delete the last node. Make sense? You have to look ahead a little as you go.
Hope this helps.
On the right, at the top of the forum, there is a box labeled "SEARCH".
Type in "return array" and select "this forum" from the drop-down box.
(The very first item returned has some good answers. Dave Sinkula's third response [post #7] is probably what you are looking to do?)
Hope this helps.
Vegaseat, you really ought to try to give people an idea instead of just writing code for them. People learn better when they can solve the problem themselves. A little direction --a nudge this way or that-- is all that is needed. (It is more satisfying both to the OP and to you who helped.)
Line 10: Never, ever, use input to get user input. That is just plain dangerous. It should read: celsius_list.append([B]raw_input[/B](prompt))
Hope this helps.
[EDIT] Just noticed (again) that you're a mod. I'm probably preaching to the choir. Sorry.
It looks like your code is a bit foggy on what it ought to be doing.
Get out a piece of paper and pencil and draw yourself a linked list, complete with little arrows pointing from node to node.
Then using the eraser and pencil change the drawing so that the last node is properly unlinked and deleted.
Do that exercise for a list of one node and a list of more than one node.
Hope this helps.
OK, here's what I was looking for.
IPC.pas by Bill Nemmers.
(If you don't want to register there you can also find it on Torry's pages.)
It is in Delphi but it should be easy enough to translate to C++ (all the actual work is done using the Windows API). Peruse it a bit and you'll see how he does it is actually pretty simple.
Hope this helps.
Hmm, as I re-read your code your "generic function" seems to me to be very un-generic --at least in the C++ sense of the word. Hence my suggestion for functors.
If you really want to use function pointers directly you will have to figure some other way to fix it. Otherwise you will need to implement it in terms of C++ generics. Here's an example:
#include <iostream>
using namespace std;
//----------------------------------------
// This is our functor class.
//----------------------------------------
// Currently it is rather simplistic as the point of a functor is
// to hold state, and this class is stateless (it has no member
// variables). In essence, it is just a callable object.
//
class ftor {
public:
int operator () ( int augend, int addend ) {
return augend + addend;
}
};
//----------------------------------------
// Here is a normal, everyday function.
//----------------------------------------
int func( int augend, int addend ) {
return augend + addend;
}
//----------------------------------------
// Here is a generic function.
//----------------------------------------
// That's "generic" in the C++ sense of the word.
// The function is used below with two different
// types of arguments, so the compiler actually
// creates two functions.
//
template <typename predicate>
void do_something( predicate f, std::string info ) {
cout << "10 + 5 = "
<< f( 10, 5 )
<< " (" << info << ')'
<< endl;
}
//----------------------------------------
// Examples of using the generic function
//----------------------------------------
int main() {
do_something( func, "using a regular function" …
You rock AD! :cool:
No, you can't, because member functions take an extra, hidden, argument this.
You might want to check out functors, which would solve your problem! (While you are at it, the entire Function Pointer Tutorials site is worth a good perusal.)
Hope this helps.
Yes. The easiest way would be to use reference parameters.
void Movie::getstuff( std::string &name, int &hours, int &minutes ) {
name = getTitle();
hours = getLength() /60;
minutes = getLength() %60;
}
Then you would call it like
std::string title;
int hour, min;
a.getstuff( title, hour, min );
std::cout << '"' << title << "\" has a runtime of "
<< hour << ':' << min << std::endl;
That said, the better way is to keep it separate like you have it.
std::cout << '"' << a.getTitle() << "\" has a runtime of "
<< a.showtime() << ':' << a.showtimem() << std::endl;
Good luck.