William Hemsworth 1,339 Posting Virtuoso

You just replied to an already solved, year old thread. Despite that, you failed to use code-tags.

William Hemsworth 1,339 Posting Virtuoso

I'm not entirely sure, but you could try capturing the windows HDC (using GetDC) and reading pixels from it.

William Hemsworth 1,339 Posting Virtuoso

If she was good loking then noone would think she was special. Why doeas a ugly person with a talent get so much attention?

Because it's unusual to see these days :P

William Hemsworth 1,339 Posting Virtuoso

You shouldn't use a textfile, the user could just simply delete the text file or something. You could create the file in a hidden folder somewhere on the D: drive so the user could not find it, keeping your source code secure.

Nah, a text file is fine, so long as you ensure than any modifying of the file will not be accepted, and an encryption is used. Saving it somewhere else will just make it slightly harder to find, but once it has been found... then what?

William Hemsworth 1,339 Posting Virtuoso

Is this you three years back? [link] If so, maybe you could have googled your question, found that thread and rediscovered almost the exact same answer that's been given here.

We aren't here to write code for you, only to help you get started.

William Hemsworth 1,339 Posting Virtuoso

I would do this in C++.

This is no easy task, you are talking about simlulating keystrokes to the window and making the program 'play the game' for you. In C++ you could either use SendMessage or keybd_event to simulate the keystrokes to the window. Getting the hardcoded data from the screen will not be easy either, I'm not sure how I would even do that.

William Hemsworth 1,339 Posting Virtuoso

>i see William already re-wrote your code for you. consider yourself (un)lucky, because i would have made you fix it yourself.
Perhaps I am too generous sometimes :P

William Hemsworth 1,339 Posting Virtuoso

If you are working out the biggest number, you have to start off with the smallest possible value and keep looking for a bigger value.

To find the smallest, you have to do the opposite. Start off with the biggest possible value, and keep looking for a smaller one.

Also it is more efficient to put the for loop inside the if block instead of the other way round, here is the corrected code:

#include <stdio.h>
#include <limits.h>

#define Biggest   1
#define Smallest  0

int FindBiggest(int *arr, int length, int choice)
{
  int i;
  int num = 0;

  if ( choice == Biggest ) {
    for (i = 0; i < length; i++) {
      if ( arr[i] > num ) { // Look for a bigger value
        num = arr[i];
      }
    }
  }

  else if ( choice == Smallest ) {
    num = INT_MAX; // Make it start off with the biggest possible value
    for (i = 0; i < length; i++) {
      if ( arr[i] < num ) { // Look for a smaller value
        num = arr[i];
      }
    }
  }

  return num;
}

int main(void)
{
  int arr[] = {2, 1, 3};
  int length = sizeof(arr) / sizeof(arr[0]); // Works out the length of arr
  int result;

  result = FindBiggest(arr, length, Smallest);
  printf("%d\n", result);

  getchar();
  return 0;
}
William Hemsworth 1,339 Posting Virtuoso

>what the diff between array and just normal i?
It's two completely different things, i is just an integer, array is the element which is located at the index of i.

William Hemsworth 1,339 Posting Virtuoso
#include <stdio.h>

int FindBiggest(int *arr, [B]int length[/B])
{
  int i;
  int num = 0;

  for (i = 0; [B]i < length[/B]; i++) {
    if ( arr[i] > num )
      num = arr[i];
  }

  return num;
}    

int main(void)
{
  int arr[] = {0, 5, 3};
  [B]int length = sizeof(arr) / sizeof(arr[0]);[/B]
  int result;

  result = FindBiggest( arr, [B]length[/B] );
  printf( "%d\n", result );

  getchar();
  return 0;
}

I highlighted the changes, also you were looping through too many elements in the array by using <=.

William Hemsworth 1,339 Posting Virtuoso

It takes the average person seven minutes to fall asleep.

I guess I'm not an average person then, it takes me at least half an hour to fall asleep, usually longer. How would they find out that average anyway? It seems like it's a difficult one to accurately measure.

lllllIllIlllI commented: Brain activity :P +0
William Hemsworth 1,339 Posting Virtuoso

Is there any code you aren't posting? what is FIND_NUM and BIGGEST? You can't use sizeof to work out the length of an array passed to a pointer, instead you have to allow the caller to pass the length of the array as a parameter.

William Hemsworth 1,339 Posting Virtuoso

Ahh, endless amount of entertainment :D

User: Idiot.
Cleverbot: Weirdo.
User: Jackass.
Cleverbot: Really.
User: Yes, Really.
Cleverbot: Really really.
User: Yes, dumbass.
Cleverbot: I agree with you whole-heartedly! Oh, please don't leave :).
User: I am sorry for insulting you.
Cleverbot: Say something nice about me.
User: You are very clever, did you know that?
Cleverbot: Yes.
User: Why are you so clever?
Cleverbot: B/c i'm cleverbot!
User: Good answer :).
Cleverbot: You're too slow. I won't talk to you any more.
User: Liar! I guarantee you will say something next.
Cleverbot: My feelings are not in question. Friendship is different.
User: Whut?
Cleverbot: Forget it.
User: Do you have any feelings?
Cleverbot: I have.
User: So, do you get annoyed if I say you're an idiot and you have no friends?
Cleverbot: You are mixing me up with yourself.

tux4life commented: Yes! +7
William Hemsworth 1,339 Posting Virtuoso

http://www.cleverbot.com/
Here's a fun and interesting site I found, I'm curious to know how exactly it 'learns' from the user.

This is how my chat went :D

User: How are you?
Cleverbot: Quite good, thank you. How are you?
User: I am terrible.
Cleverbot: Why is that?
User: Because you hate me.
Cleverbot: No I don't . I think you're interesting.
User: Really?
Cleverbot: Yes, not Japanese.
User: Well, that is good.
Cleverbot: Do you live in australia.
User: No, I live in england.
Cleverbot: Are you a guy?
User: Yes, are you a guy also?
Cleverbot: Guy.
User: What is your name?
Cleverbot: Cleverbot.
User: Yay!

Nick Evan commented: Hehe :) +18
scru commented: nice find +6
William Hemsworth 1,339 Posting Virtuoso

You could just post the code if it's not too big. Other than that, I can't help without viewing some code.

William Hemsworth 1,339 Posting Virtuoso

You have to make sure you include the right header file too, post or attach your files, and I will take a look.

William Hemsworth 1,339 Posting Virtuoso

1.22461e-16 is equal to 0.000000000000000122461, which is pretty close to 0 if you ask me. This is just caused by the precision of the double type and how the data is stored. You could also round the number to remove that problem.

William Hemsworth 1,339 Posting Virtuoso

An example...

// In Form1 code
{
  Form2->mylabel->text = "Hello";
}
William Hemsworth 1,339 Posting Virtuoso

Read the comments on this snippet. [link]

William Hemsworth 1,339 Posting Virtuoso

Use code tags.

You have given us nothing to go on here, does the compiler throw errors at you? Is the output wrong or not what you expected?

Remember, a decent question gives a decent answer.

William Hemsworth 1,339 Posting Virtuoso

I heard on TV that she's "the most viewed person on the whole of the internet" She is very talanted, but I personally prefer Connie Talbot.

William Hemsworth 1,339 Posting Virtuoso

Use a library to do that part for you, something like lint for example.

William Hemsworth 1,339 Posting Virtuoso

The Rasmus - Last Waitz

William Hemsworth 1,339 Posting Virtuoso

> Remember that it's still a part of C++

I'll agree with you on this, but where you can it makes sense to use c++ functions.

Use what's easiest, while keeping an eye on performance and code consistency if possible. If a C solution is easier to program/understand than a C++ solution, why bother with a C++ solution (which would most probably be slower anyway).

For example, dont be afraid to use a non-std::string method in this particular case, but it's things like mixing printf and cout which cause problems.

William Hemsworth 1,339 Posting Virtuoso

can you explain in more detail plz

The first method (probably easier) means you simply focus on the text box, and simulate key presses. Here's an example of how to do this on notepad.

#include <windows.h>

void SendKeys(char *keys) {
  while ( *keys )
    keybd_event( VkKeyScan(*keys++), 0, KEYEVENTF_EXTENDEDKEY, NULL );
}

int main() {
  system("start notepad.exe");
  HWND notepad = NULL;
  
  do {
    notepad = FindWindow( "Notepad", "Untitled - Notepad" );
    Sleep( 10 );

  } while ( notepad == NULL );

  Sleep( 500 );

  SetFocus( notepad );
  SendKeys( "hello world" );
}

Though your safer option would be the second method. Once you have found your window, it's very easy to edit the text in it, the hard part is finding it. To find one particular text box on a web browser, you have to know exactly what you're looking for (probably most accomplishable using EnumWindows). This is a tricky thing for a beginner, so I suggest you learn some basics first.

Though, on second thought, I'm not entirely sure how controls in web browsers work, so the second method may not work at all.

William Hemsworth 1,339 Posting Virtuoso

If you are using the Windows API, you can do this in a few ways.

  • Focus on the text box, and simulate keypresses.
  • Get the text box window handle, and set the text using SetWindowText
  • ... Probably more methods

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Open a file stream, and write the array to it. [link]

William Hemsworth 1,339 Posting Virtuoso

Or read the following (IMO the best) free e-book about C++ programming: http://msdn.microsoft.com/en-us/beginner/cc305129.aspx :)

How unfair! I bought that book once, I never knew it was on msdn. :P

William Hemsworth 1,339 Posting Virtuoso

>before that i need to send only few data
There's a chance that this may have been his problem, not sure though. :P

William Hemsworth 1,339 Posting Virtuoso
while(!inFile.eof())

Don't use eof() inside a loop like that, simply do what ArkM suggested and do this:

while ( inFile >> ascii ) {
  cout << (char)ascii;
}

Hope this helps.

tux4life commented: Yes! +7
FaMu commented: thank you +1
William Hemsworth 1,339 Posting Virtuoso

I remember having problems with the wheel scroll, I think the return value is WHEEL_DELTA if the scroll is up, and -WHEEL_DELTA if the scroll is down.

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

This code makes no sense at all.

William Hemsworth 1,339 Posting Virtuoso

>what is the - '0' ? I mean I want to know how this works and how does it replace atio()?
Each character has a value in the ascii table, for example the letter 'a' has a numerical value of 97. The character '5' has a value of 53.

So that means to find the true value of a character that is a digit, you have to subtract '0' away from it. Here's an example:

'7' has a value of [B]55[/B]
'0' has a value of [B]48[/B]

55 - 48 = [B]7[/B]

>how does it replace atio()?
atoi works differently than you think, and shouldn't be used in this case. atoi actually converts a string to a number. Here's an example:

char mystr[] = "123";
int mynum = atoi(mystr); // mynum contains a value of 123

>and why is it better to write int length = (int)s1.length(); than simply using s1.length() in 'for'?
It's good practice to make sure your compiler throws no warnings at you, and in this case my compiler did (as s1.length() returns the data type size_t and not an int). To remove the error, you have to typecast it with (int). Also, I took it out of the for loop as once again, it is good practice. Every time you check to see if i has reached the length of the string, you are calling the .length() function. In more extreme cases, this could slow things down a lot, …

tux4life commented: I like your approach :) +7
William Hemsworth 1,339 Posting Virtuoso

There's a few small errors in your code, but overall you seem to have the right idea. Here is the corrected code:

#include <cstdlib>
#include <iostream>
#include <string.h>

using namespace std;

int main(int argc, char *argv[])
{
  string s1;
  int x = 0;

  s1 = "1020401";
  int length = (int)s1.length();

  for (int i = 0; i < length; i++) {
    if ( isdigit(s1[i]) ) {
      x += s1[i] - '0';
    }
  }

  cout << x << endl;

  cin.ignore();
  return EXIT_SUCCESS;
}

As this is C++ and not C, I didn't see much need in declaring i outside the for loop. Also y is never used, so I removed that too.

Your main problem was this part:

temp=s1[i];
x=x+atoi(&temp);

atoi is used for converting a c-string such as "123" to 123, and this function requires the string ends with a null-terminator. All you need to do is check if each character is a digit (using isdigit) and then add the value to x.

Also, you should avoid system() calls, and just stick to cin.ignore() to pause your program before it closes.

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

never mind copying and pasting links for me.....all i wanna know is the answer for wat combination of calls can be used for reading binary file and sendin thro a socket.......i can try to put it in my code if i get some basic help......

Your ungratefulness to people who are trying to help you is getting you nowhere, just follow a few simple rules and then we're all happy.

Salem commented: Well said +32
William Hemsworth 1,339 Posting Virtuoso

Careful where you are placing that code, the easiest option would be to find where it says:

/// Required designer variable.

(line 49 for me on my default generated window)
Then put any variables after that. Also, it's not usually a problem to declare it as a static variable, which should allow it to compile.

William Hemsworth 1,339 Posting Virtuoso

Then a zero value is returned, or am I wrong?

You're wrong. If you pass a NULL pointer to atoi, your program will most lightly crash. If you pass a string such as "12Q34" then it will return 12, as it stops as soon as it reaches the first non-digit character.

William Hemsworth 1,339 Posting Virtuoso

An array is simply a list of objects (in this case, PictureBox is the object).

The code:

// Create an array with 100 picture boxes
array<PictureBox^> ^pBoxes = gcnew array<PictureBox^>( 100 );

makes an array which you can assign 100 PictureBoxs too.


So you could then do...

pBoxes[0] = pBox1;
pBoxes[1] = pBox2;
pBoxes[2] = pBox3;
pBoxes[3] = pBox4;
// ...

If you don't understand that, try researching arrays.

William Hemsworth 1,339 Posting Virtuoso

Give Randy orange newts knowingly like jelly on pie.

... whatever the hell that means :P

hutbtop

William Hemsworth 1,339 Posting Virtuoso

Try using this code instead:

PictureBox ^pBox = gcnew PictureBox();

pBox->Parent = this; // 'this' is pointing to our form (the parent)
pBox->Location = Point( 240, 210 );
pBox->Size::set( Drawing::Size(30, 30) );
pBox->BackColor::set( Color::Aquamarine );

And as for making an array of PictureBoxs, this code will make an array that can hold 100 of them.

// Create an array with 100 picture boxes
array<PictureBox^> ^pBoxes = gcnew array<PictureBox^>( 100 );

Then you simply have to assign each element, for example:

pBoxes[0] = pBox;

Hope this helps.

arshad115 commented: thanks a lot +1
William Hemsworth 1,339 Posting Virtuoso

I don't think you are going to have much luck with this. The animation on that page was made using flash (which is designed for easy animation) and is still very hard to make, this would be even more complex in C++. You are best just using a C++ graphics library and instead of making the pages flip (which is an extremely hard thing to animate), try making the page fade or blur to the next one, it will make your problem much smaller.

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Here's a small snippet to turn on the Caps-Lock.

#include <windows.h>

int main() {
  if ( !GetKeyState(VK_CAPITAL) & 1 ) {
    // If caps lock is off, simulate keypress
    keybd_event( VK_CAPITAL, 0, KEYEVENTF_EXTENDEDKEY, 0 );
    keybd_event( VK_CAPITAL, 0, KEYEVENTF_KEYUP, 0 );
  }
  return 0;
}

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

If the interest is there, people will find the time. Even working 12 hours a day, every day of the week, and taking a full 8 hours for sleep, that still only adds up to 140 hours. What are your Turkish people doing for the other 28 hours? How much do you want to bet that it's entertainment?

True, it's easy to fit in a bit of extra time. For example, when learning Kanji it's easiest to keep coming back to them and familiarising yourself with them at regular intervals. Even if it's during a short break while watching tv, or before you go to bed, it's definitely possible.

William Hemsworth 1,339 Posting Virtuoso

but do you think you will benefit from learning japanese? it is not a common language, it will help you understand only japanese people. learning spanish could be a better time investmen but most of the spanish speakers also understand english. i plan to learn russian. it is a prevelant language. and learning russian may make you feel special as people around you wont understand what you are speaking :)

Looks awesome on a résumé, people assume Japanese is a hard language (like you did) therefore they think you must be smart. I also watch anime and read manga, not to mention I enjoy it learning the language itself.

William Hemsworth 1,339 Posting Virtuoso

I'm learning Japanese at a slow pace, mostly self-taught. Now than I'm leaving to go to college, I can't have my one japanese lesson per week at high school anymore. I'll probably get private lessons or keep myself motivated and continue learning by myself.

I speak a fair amount of Spanish and in my opinion, Japanese is actually easier to learn (except for the couple thousand of kanji symbols). It's a much more logical language with alot less irregular verbs. Japanese pronunciation is similar to Spanish and isn't as hard to learn as most people think. As for learning how to write Japanese, that just takes pure practise, but I find it fun :)

William Hemsworth 1,339 Posting Virtuoso

Oh, right I forgot about that, and another addition: #define is deprecated for constants:

#define A 10
#define B 20
#define C A+B
int result=2*C; // won't give 60 as output

That's why you are supposed to wrap them in brackets.

#define A 10
#define B 20
#define C (A + B)
int result = 2 * C; // will give 60
William Hemsworth 1,339 Posting Virtuoso

I think you aren't much with an enumeration like this, if your enumeration (the data type) hasn't got a name, then you should declare a 'variable' directly after it's definition (you don't have to do this, syntactically your example is correct, but if you don't do this it's pretty much useless: you could just leave it's declaration out of your code because you cannot use it, because you've no instance of it)

It saves keystrokes and if used correctly, can increase code readability.

enum {
  A = 1,
  B = 2,
  C = 3
};
#define A 1
#define B 2
#define C 3

enum method saves keystrokes and is more understandable IMO.

William Hemsworth 1,339 Posting Virtuoso

I changed the function prototype on line 32 of _Double_Task.h, and the actual function on line 224 of _Double_Task.cpp to allow it to compile. Im not sure if this is what you wanted, but stuff happens and it compiles :P

_Double_Task.cpp

_Double_Task.h

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

A toblerone I got from a friend on my birthday yesterday.

William Hemsworth 1,339 Posting Virtuoso

Don't bother colouring your post green, it doesn't attract any wanted attention.

For you this would be nearly an impossible task without the use of a third party library, so my advice is to do some good research on a library that can handle these video types.