Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

there are 26 cards in a deck, so generate a list of 26 unique but random numbers. Then if you have a list of cards, just pick them out in the order of the random numbers previously generated. It would be a lot easier to use an vector or list of 2-char strings instead of putting them into all one string.

To remove the first card just erase the first string in the vector or list, then suffle the strings that remain in the vector.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>tell me what to do so as i can start downloading games again

you could reformat the entire hard drive then resinstall the operating system:mrgreen:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The backspace erases the character underneath the cursor just like it does when you type it on your keyboard. Is that what you want?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No, there is no such function. If you want the cursor at the end, use an operating system specific function to move it there after the text is printed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can clear the entire screen using the cleardevice() function and redraw the square in a loop with the new positions.

Yes he could, but that's not what he wants to do. And it would look terrible and be awfuly sloooooow if there were a lot of graphics on the screen such as you might see in games.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I hate feeling dumb.
we all felt like that at first. So don't worry about it and just keep studying. You'll get the hang of it.

>>I don't need the do?
No -- it is a language-specific key word and loop type.

There are lots of other ways to solve the problem, but if you have to just change the pseudocode they gave you then asking the same question twice is the best way. Ask the question before the loop starts then again just before the loop ends.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

To erase the square, redraw it in the same color as its background.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I don't even know what kind of language it's in
It is pseudocode, which means it is not written in any computer language. Its purpose is to show the logic regardless of programming language.

What you will want to do is copy the input line (do NOT just move it) to the end of the loop immediately after the print line.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

did you include time.h? Also, if you are compiling as c++ then change variable end to something else because end is a c++ key word.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

see my second example -- you have to get the time before processing starts and again after, then subtract the two. And the time is in whole numbers. If you want fractions than divide by 100 when printing it.

print ("time = %f\n", (float)processing_time/100.0F);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hi, just looking for a quick answer to my problem:
How can I read a string from a binary file?
for example

string buff;
binfile.read(reinterpret_cast<char*>(&buff), 10)

does not work. Doesn't work either if buff is declared as a c-style string.
I'd preferably like to read it into an STL string. Thanks.

Of course it doesn't work -- you are passing a pointer to a c++ object to a function that wants a char*. And you are fooling the compiler into thinking that YOU are correct, which you are not.

char buf[11];
binfile.read(buff, 10) ;
// null-terminate the string.  This assumes that the
// length of the string is known -- 10
buf[10] = 0;
// now create the c++ string object
string str = buf;

You have to know the contents of the binary file for the above to work -- if the file contains variable-length strings then the file must also contain something that indicates the length of the string, such as preceeding the string with its length, or the file contains a null character that indicates the end of the string. Either of these conditions makes your program a little more complex.

The code above should work if the strings are fixed-length strings, in the example the length of the string would always be 10, if shorter than 10 then the string in the file would have to be padded with spaces to force it to 10 characters.

Without knowing more …

John A commented: Good info. -joeprogrammer +5
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

that's really crappy code you posted :cheesy:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

make a parameter that is a pointer to the object you want the function to return Example:

int foo( size_t* time)
{
    *time = 123;
    return 1;
}

int main()
{
    size_t processing_time;
    int x = foo( &processing_time );
}

If you want to profile the entire function then the function doesn't need to know anything about it.

int main()
{
    time_t start, end;
    start = time(0);
    foo();
    end = time(0);
  // now just subtract the two times to get processing time

   return 0l;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>>>The function you posted will return the ascii code, not the scan codes

I still say that, it returns, scan code
try with any character key like 'A','s', etc.
& guess, they r same for any keyboard!

int 16 returns the scan code in ah and the ascii value in al. If you really want the ascii value then get it from al. When the value of ah is 0 that means someone hit one of the special keys, such as function and arrow keys. In that case you have to call int 16 a second time to get its values. The ascii value of special keys are the same as normal keys. There are several ways to handle that -- one way is to add 255 to the ascii value of special keys, another way I've seen is to make them a negative value. You have to do that so that the rest of the program knows how to interpret the value returned by that function.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The function you posted will return the ascii code, not the scan codes, which are the same codes that are returned by getc(). It should work ok with 16-bit MS-DOS compilers such as Turbo C, but will not work with any modern 32-bit compiler because the platform (protected-mode programs on Intell chips) will not allow the program to call any of the ms-dos interrupts.

And your code is very similar to the code in the link I provided in an earlier post to this thread.


Here is a link to some assembly code you might find useful

And an int 16h TSR that hooks into int 16

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>s there any way to detect this without using winAPI or any other standard APIs???

No. The only way to get mouse clicks is via operating-system specific calls. And I beleve we have told you that several times in this thread.

>>ay, if anybody want to detect, F1 or ESC, or any such key, wat according to u can be, or shall be done ?

You are confusing scan codes and ascii key codes. They are not the same, so you need to get your terminolory straight. You can use the ascii codes returned by getc() to do what you want, as already demonstrated in this thread. I even posted a link to c code snippets that showed how to do it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Some example free programs for MS-DOS, MS-Windows in C and assembly

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is the link I mentioned earlier. It contains some code you can download that demonstrates how to write console program using win32 api functions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have a question too:
I want to use functions like "delay" or "gotoxy". Eventhough I include the dos.h header file AND added it into my projects "Header files" the compiler still doesn't recognize those functions.

What am I doing wrong?

Thanks
Ami

That's right -- VC++ 2005 Express and other 32-bit MS-Windows compilers do not support those header files. gotoxy() is not supported either, but Sleep(int milliseconds) found in windows.h can replace delay() from your old borland compiler.

win32 api has a whole set of console functions that allow you to move the cursor something like you did with gotoxy(). You might want to write your own gotoxy() that is a wrapper for those win32 api functions. See this MSDN entry. There are also a few tutorials on the net -- I don't have them available right now but I can look up the link in about 4 hours or so.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Nice link Colin. I just tried it and it worked great.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have a boss once that required comments on each and every line of code. He was not proficient in computer languages but wanted to read and understand their logic. Now that is overkill.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The scan codes not standard -- they are different for every keyboard. But if that is what you want, here it is.

Unless you want to write your own keyboard device driver I see no real use for those codes. What, if anything, can you do with them? I have never had an occasion to use them in the past 20+ years. As far as I know there are no standard C functions to get scan codes. You may have to write a hook into the keyboard device driver so that you can capture the codes. I know there are some win32 api functions that return the scan codes, but that of course is non-c standard. I have no clue how to do it in *nix

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

please answer Salem's question -- what compiler and operating system are you using?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is a very good introduction to win32 api programming. Its only a brief introduction to get you started.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You will want to create a file with *.c extension and VC will compile it as a c file, not c++. Create a new empty project. Then add a new file, when you give it a file name also specify the *.c extension -- such as myfile.c. How you do all that depends on what version of VC you have. VC++ 6.0 is not the same as VC++ 2005 (the most recent version).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is an example of one way to get keyboard input. If you want your program to continue doing something else then yes, you will want to create a thread for the keyboard input function.

>>also.. where will this ascii value corresponding to the keypress be stored?
wherever you want to store them -- that is up to you. What action do you want your program to take when a key is pressed? I assume you want the program to respond to keypresses.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

ads are a necessary evil to the survival of DaniWeb, or any other free site. I would rather see a few ads than be forced to pay a monthly fee like some sites require. I did see one ad the other day I thought was inappropriate -- "We'll do all your homework for you (for a price of course)" was the subject.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I declare this "Psuedo-Science"

Its more like "VooDoo Science", very similar to horoscopes.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Start by going to the Game Development board and read the sicky threads at the top of the board. It contains a list of the resource you might want.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Bcoz, u feel it is so easy to find it on GOOGLE.
.

yes this one is EASY to find with google -- its the first link that appears. If it was difficult to find then I would have posted a link to it, but its not so I won't. Aspiring programmers have to learn how to do your own research because that's what will be expected of you when you get on a job. Now is just as good a time as any to learn that.

Trust me dude, the code is most useful in any proffessional software (made in C)

There is no code involved -- its only a table of integers that are assigned to each of the 255 possible key values. Also, we were never asked for code -- just function names, and we all answered that question several times. Writing the code to use those functions is an entirely different matter -- google is next to useless for that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>just wondering if there is anymore documentation that I woould need?

don't know -- depends on your teacher's requirements.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

then u provide the code Mr.Ancient Dragon ! vbrep_register("302561")

are you asking ME to do HIS research for HIM :eek: I don't think so -- his fingers can type in the google command just as easy as mine -- and he will get the information a lot faster too.

>>vbrep_register
what's that?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>ya.. the code wud be nice.. if it`s not much of a problem
google for "ascii chart" and you will get all 255 codes

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

maybe this will help you

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Heh. On WinXP I got "Skipped unknown compression method." I thought it was just me. :lol: I can see the file names, but I can't unzip them. Or is this an NSA challenge? :p

Jeff

I just now unziped it without any problems using WinZip on XP. I don't have *nix computer so can not test it there.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I've seen flour mills here in USA, I've visited them a few times. Extremly dirty and dusty -- flour all over the place. By the time your shift is over you will look like someone dumped a 50 lb sack of flour over your head. As for taking electronic equipment there -- forget it because it won't last five minutes in all that flour dust.

As for "Living off the land" -- farmers to that. If you want to do it then get a job on a farm.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

softward development costs can vary widly depending on the programmer and your location. In my location it might cost from $50.00 per hour up to $100.00 or more per hour. You will have to first develop a detailed design of what you want the program to do and what the screen(s) should look like, including any graphics menus, buttons, etc. The more detailed you get the better off you will be. Once you and the programmer decide on the project the design is pretty much set in stone -- it can not be changed without also re-negotiating the price of the project.

You will want to write a contract that you and the programmer will both sign, and you should have a lawyer in your state or country review it to make sure it meets all legal requirements. One provision of the contract might be that you, not the programmer, retain ownership and all copyrights to the software.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

did you try any of these google links?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>'m having trouble unzipping it on Linux.
are you using gzip ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You should be able to install the C# program on a single network computer, create a shortcut to it on each client computer, then run an instance of it on each indivual client computer. You may have to change the connection string in the C# program to point to the machine on which the database is running, unless you have already done that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

to write a wrapper means to write your own function that will eventually call some standard library function

Now, instead of calling fgets() call myfgets()

char* myfgets(char *buf, size_t bufsize, FILE* fp)
{
    chr* ptr = NULL;
    // validate parameters
    if( buf != NULL && bufsize > 0 && fp != NULL)
    {          
        ptr = fgets(buf,bufsize,fp);
        if(ptr != NULL)
       {
            size_t len = strlen(buf);
            if( buf[len-1] == '\n')
               buf[len-1] = 0;
       }
    }
    return ptr;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>But does it really matter which one is faster?
Yes it might, depending on how often it is used and whether it is a real-time program or not. How many programs have you used that are sluggish and show to respond -- one reason is for careless programming and programmers not paying attention to efficiency.

It would appear from your comments that you have never written a real-time program where you have to sequeeze every last nano-second you can out of the program. No reflection on you but what you stated is a common belief about program speed/efficiency versus program maintainability. Sometimes ease of maintainance issues have to be sacrificed for program efficiency.

>>I would use a wrapper function or write my own version of fgets to suit my application.
Yes, that is the best solution if there are a lot of fgets()'s scannered throughout the program.

> Since '\n' is always the last character in the buffer there is no point using those functions
No it isn't.
If the line is longer than the buffer, then there will be no \n in there at all, so just trashing the character before the \0 is wrong.

you are of course correct but I made no mention of that. If it exists it will always always be the last byte just before the null terminator.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Since '\n' is always the last character in the buffer there is no point using those functions -- they are a waste of time and will do nothing more than slow down the program if used frequently. My opinion is that it is a misuse of those functions.

strlen() to an index or pointer are one in the same -- I prefer index method as in the example I posted

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>native functions in C with which i can detect a keypress

getchar() and getc()

>>native functions in C with which i can detect a keypress
no C functions for the mouse.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I wouldn't say it appends it, but rather leaves it there if in fact it is there. And with very long strings, it seems a waste to calculate the length twice. (I mentioned this to a seasoned programmer in a slightly different light once long ago, so that is why I mention it again here. That problem involved nested loops and strlen and severe performance issues, which is why I feel it is worthy of mention -- it's not a good habit to perpetuate.)

I agree -- in actual programs I calculate the length only once and probably should have shown that method here too.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

MS-Windows fgets() appends a '\n' at the end of the line, which you must remove.

while (fgets( // blabla ) )
{
   if( line[strlen(line)-1] == '\n')
      line[strlen(line)-1] = 0;
}

If the above doesn't fix the problem, look at the file with Notepad.exe and see if those characters are there. If they are, then the problem is in the data file and not your program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>which it should have, given the warning
All the compiler cares about is that you pass a pointer -- even a dummy pointer will satisfy that requirement. Its up to you pass a pointer to a valid object. Many win32 api functions validate the pointer is not NULL, and if it is NULL then the function returns without doing anything.

And don't forget to always check the return valid of those functions. Don't just assume they will return success because often they don't.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You created the pointer but where is the memory allocated to it ? How do you expect the GetCursorPos() to return anything to a mere pointer to whom no memory has been allocated ?

In your declaration of LPPOINT variable do this: LPPOINT lpPoint = new POINT ; And then it should be fine.

Hope it helped, bye.

there is no need to allocate memory like that. Just see my previous post for correct way to do it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
fgets(line,LINE_BUF,fp); 
          while (!feof(fp))     {

The behavior you see is probably because the above is not the correct way to code that loop. Here is the correct, and more efficient, way. Not how eof() function is not needed.

while( fgets(line,LINE_BUF,fp) != NULL)
{
   // blabla
}

You did not post the declaration of ListNode, but I assume member word is an array of characters and not a pointer. Your program might be more efficient if you make word a pointer and allocate the required length. Sure, strncpy() will help minimize buffer overflows, but if the source string is longer than the amount of space allocated for the destination string, the result destination string will not be NULL terminated, and that will make other standard string operations (such as strlen) unpredictable.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

GetCursorPos() expects a pointer of type POINT. All you are passing is a pointer to nothing.

POINT pt;
if( GetCursorPos( &pt ) != 0)
{
   // pt contains valid data.  Now you can use is however you wish

}

Whenever windows.h says a parameter to a function is a pointer, it means you must pass it a pointer to an object that you create, such as in the code snipped above. That sort of thing happens in most win32 api functions. It is ALWAYS a pointer to your object, unless the documentation in MSDN says otherwise.