I looked around for a while. I'm going to use SendInput now. It works.
TheBeast32 54 Posting Whiz in Training
John A commented: Congratulations for doing someone else's homework. -3
I looked around for a while. I'm going to use SendInput now. It works.
If the file is in the same directory couldn't you just do this?
#include <conio.h>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
string FileName;
cout << "Enter the file name: ";
cin >> FileName;
cout << endl << endl;
ifstream in(FileName.c_str());
while (!in.eof())
{
char ch;
in.get(ch);
cout << ch;
}
getch();
return 0;
}
Example:
Enter the file name: Stuff.txt
Stuff.
Never mind. I found out how to do it. Thanks anyway.
Hi, how would I use mouse_event to simulate the mouse wheel? I can only do clicks.
void Left_Click(const long x, const long y)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP,x,y,0,0);
}
void Right_Click(const long x, const long y)
{
mouse_event(MOUSEEVENTF_RIGHTDOWN, x, y, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTUP, x, y, 0, 0);
}
Hi, I need a way to see if a mouse button is up or down, if the wheel is being used, and if so, which direction the wheel is moving using a hook or something like that. MSDN didn't help me much. Also, I'm using Dev-C++ 4.9.9.2.:yawn:
This is a little long, but it works!
#include <string>
#include <iostream>
using namespace std;
int main()
{
string word1, word2, word3;
cout << "Enter word1: " <<endl;
cin >>word1;
cout <<"Enter word2: " <<endl;
cin >>word2;
cout << "Enter word3: " <<endl;
cin >>word3;
int Longest, Shortest;
// Get the longest word
if (word1.length() > word2.length() && word1.length() > word3.length())
{
Longest = 1;
cout << "\nLongest word: " << word1;
}
if (word2.length() > word1.length() && word2.length() > word3.length())
{
Longest = 2;
cout << "\nLongest word: " << word2;
}
if (word3.length() > word1.length() && word3.length() > word2.length())
{
Longest = 3;
cout << "\nLongest word: " << word3;
}
// Get the shortest word
if (word1.length() < word2.length() && word1.length() < word3.length())
{
Shortest = 1;
cout << "\nShortest word: " << word1;
}
if (word2.length() < word1.length() && word2.length() < word3.length())
{
Shortest = 2;
cout << "\nShortest word: " << word2;
}
if (word3.length() < word1.length() && word3.length() < word2.length())
{
Shortest = 3;
cout << "\nShortest word: " << word3;
}
// Get the word in the middle
if (Shortest == 1 && Longest == 2)
{
cout << "\nOther word: " << word3;
}
if (Shortest == 2 && Longest == 1)
{
cout << "\nOther word: " << word3;
}
if (Shortest == 1 && Longest == 3)
{
cout << "\nOther word: " << word2;
}
if (Shortest == 3 && Longest == 1)
{
cout << "\nOther word: …
Hi, i need to make a very large char array (char array[10000000]). How would I do this without getting a stack overflow error?
That works perfectly! Thank you.
Thanks, I'll revise my code and try it.
Hi i have been making two programs: one that sends a file's filebuf made into a char*, and another that receives that and writes it to a file. They're like exe sending programs. I can send the char* and write it onto the console using cout.write(), but when I try to copy it onto a file, it will only be like 3 bytes in size while the original file is 500kb. How would I write it correctly? I don't want to show all of my code because that would take up space, and most of it is irrelevant. I will just show the sending, receiving, and writing.
Sending:
ifstream in(FileName,ios::binary);
if (in)
{
filebuf *pbuf;
pbuf = in.rdbuf();
long size;
size = pbuf->pubseekoff(0,ios::end,ios::in);
char * buffer;
buffer = new char[size];
pbuf->pubseekpos(0,ios::in);
pbuf->sgetn(buffer,size);
if (send(sClient, buffer, strlen(buffer), 0) != SOCKET_ERROR)
{
cout << "\nSent file successfully!";
}
else
{
cout << "\nError sending file!\n";
}
}
Receiving and Writing:
char cClientMessage[500000];
recv(sClient, cClientMessage, 499999, 0);
ofstream out(TempFileName.c_str(), ios::binary);
string ConfirmString;
if (out)
{
out.write(cClientMessage, strlen(cClientMessage));
ConfirmString = "Successfully copied file! New file name is ";
ConfirmString += TempFileName;
out.close();
}
else
{
ConfirmString = "Error copying file!";
}
send(sClient, ConfirmString.c_str(), ConfirmString.length(), 0);
}
I just looked it up on google. It said it was a "Bell Character" or something like that.
Hi, I have a question: What is the mysterious beep on a console program? I made a program that reads a *.exe file then displays it on the screen. I got a massive amount of beeps! Another example of a mysterious beep is: Open Command Prompt, Press Ctrl+G, then hit enter. It will beep? Why does this happen and how can I make it stop?
Hi, I made a simple program that copies files. I tried to copy an exe file, but after I tried to run the copied version, it doesn't work properly. Please help:?:
Here's the code for the test file to copy:
#include <iostream>
int main()
{
std::cout << "Hello!";
std::cin.get();
return 0;
}
And the copier:
#include <fstream>
#include <conio.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string OldFile, NewFile, OldContents;
cout << "Enter file to copy: ";
cin >> OldFile;
cout << "\nEnter a new file name: ";
cin >> NewFile;
ifstream in(OldFile.c_str(),ios::binary);
if (!in) return 0;
char temp[100000] = {0};
in.read(temp, 100000);
OldContents = temp;
in.close();
cout << "\nDone reading!";
ofstream out(NewFile.c_str(), ios::binary);
if (!out) return 0;
out.write(OldContents.c_str(), OldContents.length());
cout << "\nSuccessfully copied file!";
getch();
return 0;
}
Thanks, that helps a lot! =)
Ok, how would I put the date at the end of the *.exe file? I want it to bee as secure as possible. I have heard of a lot of programs that can decode a hash, so I don't want to use the registry or a file.
How would I store it in the *.exe file?
Hello, I have been wondering how to keep a value even after a program ends. An example could be a countdown of days on a trial of a product. It must be able to not be changed by the user. How would I do this?
Hi, i'm finally able to respond. I have a 2.50 mghz Intel Celeron CPU 479 mb ram. I am using Dev-C++ 4.9.9.2. Ill make the loop shorter, but how long does it need to be?
I have made someyhing like this before.
Here it is:
bool CheckPrime(unsigned long num)
{
unsigned long long int x = 2;
bool prime;
if (num < 4)
{
switch (num)
{
case 1:
prime = false;
break;
case 2:
prime = true;
break;
case 3:
prime = true;
break;
case 4:
prime = false;
break;
}
}
else
{
while (x < (num / 2) + 1)
{
if (num % x == 0)
{
prime = false;
break;
}
else
{
prime = true;
x++;
}
}
}
return prime;
}
Hi, I have been making a program that searches in another process's memory for a value from the user. It works, but it's very slow. I have used other searchers like TSearch that are really fast. If anyone has a way to make it faster, please help.:-/
Here's my code
#include <windows.h>
#include <iostream>
using namespace std;
int Memory(HWND MyWindow, int long Address, int Value, bool _w)
{
DWORD PROC_ID;
HANDLE PROC_HANDLE;
GetWindowThreadProcessId(MyWindow, &PROC_ID);
PROC_HANDLE = OpenProcess(PROCESS_ALL_ACCESS, false, PROC_ID);
if(_w)
WriteProcessMemory(PROC_HANDLE, (LPVOID)Address, &Value, sizeof(long int), NULL);
else
ReadProcessMemory(PROC_HANDLE, (LPVOID)Address, &Value, sizeof(long int), NULL);
CloseHandle(PROC_HANDLE);
return Value;
}
int main()
{
SetConsoleTitle("Memory Search");
unsigned long long int x;
LPVOID MyLPVOID;
char Caption[1000];
cout << "Enter the caption of the window: ";
cin.getline(Caption, 1000);
HWND Test = FindWindow(NULL, Caption);
if (!Test)
{
cout << "\nCannot find window \"" << Caption << "\"!";
cin.get();
return 0;
}
LPVOID Address;
cout << "\nEnter the address to start at: ";
cin >> Address;
int WhatToFind;
cout << "\nWhat number are you trying to find: ";
cin >> WhatToFind;
for (x = 0; x < 2000000000; x++)
{
int AtAddress = Memory(Test, ((int long)Address + x), 0, false);
if (AtAddress == WhatToFind)
{
cout << "\n\nFound it at address: " << (LPVOID)((int long)Address + x);
cin.ignore();
cin.ignore();
}
}
cout << "\nDone!";
cin.ignore();
cin.ignore();
return 0;
}
I have Dial-up so i have no router and my gateway is myself and sry for replying so long, i had to go
Hi, i have been making a server for a client I made to connect to. I don't have a static IP, so I need a way for someone on another computer to connect to me without me telling the user what it is every time.
I have tried to just enter another IP in the inet_addr() funtion but then it can't bind.
Please Help...:confused:
SOCKET sServer;
sServer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(sServer == INVALID_SOCKET || iError == 1){
MessageBox(NULL, (LPCTSTR)"Invalid Socket!", (LPCTSTR)"Server::Error", MB_OK|MB_ICONERROR);
WSACleanup();
return 0;
}
SOCKADDR_IN sinServer;
memset(&sinServer, 0, sizeof(sinServer));
sinServer.sin_family = AF_INET;
sinServer.sin_addr.s_addr = inet_addr("127.0.0.1"); // Where to start server?
sinServer.sin_port = htons(1000); // Port
if(bind(sServer, (LPSOCKADDR)&sinServer, sizeof(sinServer)) == SOCKET_ERROR){
/* failed at starting server */
MessageBox(NULL, (LPCTSTR)"Could not bind the server!", (LPCTSTR)"Server::Error", MB_OK|MB_ICONERROR);
WSACleanup();
return 0;
}
Could anyone tell me if there is a function like the InputBox() function in Visual basic? I have googled it and come up with nothing. Thanks.
Hi again, i'm making a macro building pogram. I have got mouse movement down, but now i have no idea how to do mouse clicks or keyboard input. Please help! I'm also using dev-c++ 4.9.9.2.
Here's my complete code for the program.
POINT MousePoint;
int X = 0;
int Y = 0;
int MaxTime = 0;
int Counter = 0;
int NumOfResults = 0;
int Xmax, Ymax = 0;
int InputNumStr = 0;
char Action = 'a';
int TempInt, InputInt = 0;
char FileName[256] = "AAAAAAAAAAAAAAAAAAA";
char TempStr[256] = "AAAAAAAAAAAAAAAAAAA";
BOOL SetX = TRUE, SetY = FALSE;
#include <windows.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include "Macro.h"
using namespace std;
int main(int argc, char* argv[])
{
cout << "MacroBuilder V. 1.0" << endl;
cout << "\nEnter the name of the macro: ";
cin >> FileName;
strcat(FileName, ".txt");
std::ofstream SaveFile(FileName);
SaveFile.close();
cout << "Type 'r' to record, 'q' to quit, 't' to test, or 'p' to play";
cin >> Action;
while (Action != 'q')
{
switch(Action)
{
case 'r':
MaxTime = 0;
Counter = 0;
NumOfResults = 0;
cout << "Enter the max time of the macro in seconds: ";
cin >> MaxTime;
MaxTime = MaxTime * 10;
cout << "\nPress escape to stop recording\n";
system("pause");
system("cls");
while (MaxTime > Counter)
{
GetCursorPos(&MousePoint);
if (MousePoint.x < 10)
{
std::ofstream SaveFile(FileName, ios::app);
SaveFile << "000" << MousePoint.x;
SaveFile.close();
cout << "\nX: 000" << MousePoint.x;
}
else if (MousePoint.x < 100)
{
std::ofstream SaveFile(FileName, ios::app);
SaveFile << "00" << MousePoint.x;
SaveFile.close(); …
OH!, I figured it out!!! thanks everyone, nowi got it.
whoops! Mine doesn't work either!
I dont know what to do now.........
Thank you all for your help!!
I made my own code based on your idea though.
it's right here:
#include <iostream>
using namespace std;
int main()
{
int factor1, factor2;
bool prime = true;
cout << "Enter a number";
int num;
int x=2;
char stopchar;
cin >> num;
while (x < (num / 2) + 1)
{
if (num % x == 0)
{
prime = false;
}
else
{
prime = true;
}
cout << x;
x++;
}
switch (prime)
{
case true:
cout << "it's prime";
break;
case false:
cout << "it's not!";
break;
}
cin >> stopchar;
return 32;
}
Why make your code so complicated? The most basic concept of finding prime is to test from 2 until number-1. Once you find the divisor number of that number, then you are also able to find the factor of that number.
int factor1, factor2; bool prime = true; for(int i=2; i<num; i++) { if (num%i==0) { prime = false; factor1 = i; factor2 = num/i; break; }
To improve the proformence speed, you don't need to test from 2 to number-1; you can simply test it until number/2
bool prime = true; temp = num/2; for(int i=2; i<=temp; i++) { if (num%i==0) { prime = false; factor1 = i; factor2 = num/i; break; }
To improve even more proformence speed, you can test it only test it until sqrt(number).
bool prime = true; temp = sqrt(temp); for(int i=2; i<=temp; i++) { if (num%i==0) { prime = false; factor1 = i; factor2 = num/i; break; }
I just tried that.
Whenever i entered an odd number, it said it was prime.....
Maybe it's just me or someting, but it didn't work
Thanks, and sorry for getting back so long, I had to go.
I have been making a prime number generator.
It works, but it's considerably slow if a user enters a high number. If anyone has any suggestions on how to make it faster, please post it.
Here's the genrator code:
unsigned long int theNumber;
unsigned long int Factor1 = 1, Factor2 = 1;
//-----------Find the prime number-----------------
do
{
Factor2 = 1;
Factor1 += 1;
if (Factor1 * Factor2 != theNumber)
{
isPrime = FALSE;
} // End if
else
{
isPrime = TRUE;
} // End else
while (Factor1 < (theNumber / 2) + 1 && Factor2 < theNumber && Factor1 * Factor2 != theNumber)
{
Factor2++;
if (Factor1 * Factor2 != theNumber)
{
isPrime = FALSE;
} // End if
else
{
isPrime = TRUE;
} // End else
} // End while
} while (Factor1 * Factor2 != theNumber); // End do
//-------------------Done finding------------------
// Display the results
switch (isPrime)
{
case TRUE:
cout << "\n Hurray! It's a Prime Number!";
break;
case FALSE:
cout << "\n Sorry, It's Not a Prime Number.\nThe two factors we found were: " << Factor1 << " and " << Factor2 << ".";
break;
} // End switch
oops nvm
Apparently my code has smileys in it. ifnore tham plz
Hi, i have been making a program that tests a computer owner's firewall. It gets input from the client i made, and does a system() with it. Is there any way to make the firewall not block the program right when i make a scocket?
Oh, im using Dev-C++ 4.9.9.2 also.
Here's my code for my server so far:
#include <windows.h>
#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
int main(int argc, char *argv[]){
// Create Stealth
HWND hWnd;
AllocConsole();
hWnd = FindWindow("ConsoleWindowClass", NULL);
ShowWindow(hWnd, 0);
// Done!
WSADATA t_wsa; // WSADATA structure
WORD wVers; // version number
int iError; // error number
wVers = MAKEWORD(2, 2); // Set the version number to 2.2
iError = WSAStartup(wVers, &t_wsa); // Start the WSADATA
if(iError != NO_ERROR || iError == 1){
MessageBox(NULL, (LPCTSTR)"Error at WSAStartup()", (LPCTSTR)"Server::Error", MB_OK|MB_ICONERROR);
WSACleanup();
return 0;
}
if(LOBYTE(t_wsa.wVersion) != 2 || HIBYTE(t_wsa.wVersion) != 2){
MessageBox(NULL, (LPCTSTR)"Error at WSAStartup()", (LPCTSTR)"Server::Error", MB_OK|MB_ICONERROR);
WSACleanup();
return 0;
}
SOCKET sServer;
sServer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(sServer == INVALID_SOCKET || iError == 1){
MessageBox(NULL, (LPCTSTR)"Invalid Socket!", (LPCTSTR)"Server::Error", MB_OK|MB_ICONERROR);
WSACleanup();
return 0;
}
SOCKADDR_IN sinServer;
memset(&sinServer, 0, sizeof(sinServer));
sinServer.sin_family = AF_INET;
sinServer.sin_addr.s_addr = INADDR_ANY; // Where to start server?
sinServer.sin_port = htons(1000); // Port
if(bind(sServer, (LPSOCKADDR)&sinServer, sizeof(sinServer)) == SOCKET_ERROR){
/* failed at starting server */
MessageBox(NULL, (LPCTSTR)"Could not bind the server!", (LPCTSTR)"Server::Error", MB_OK|MB_ICONERROR);
WSACleanup();
return 0;
}
while(listen(sServer, 20) == SOCKET_ERROR){
Sleep(10);
}
MessageBox(NULL, (LPCTSTR)"Waiting for a Client!", (LPCTSTR)"Server::Success", MB_OK);
int MaxCmds = 100;
int NumOfCmds = 0;
while …