Ok so first off you going to use strings... you can use strcmp() for comparing two strings such as Game: "adam ahs joined the game" compared to " " has joined the game... then itll basically tell you who joined the game... for the second part you can use
sk.SendKeys(" Adam Has Joined the game ");
triumphost 120 Posting Whiz
well as far as the copy three times your going to need a loop like do{code} until... give button pressed... secondly ur going to want the file to be appended each time it was pasted so ur going to want to use filename.append ++ which can be into a loop also so u can append the filename for everytime the loop repeats itself
triumphost 120 Posting Whiz
I cant exactly read programs with header included but i can read full on programs where all the code is put together rather than separating part with a header... but I can tell you, usually when a program doesnt stop and it keeps going on when u enter something, it has to do with your loop. maybe your loop goes on until it gets to the last member and then it starts to print output... instead u can change it to make it output after each member is called... Im pretty sure its either the loop or your print function... I dont know but I see that you loop keeps going until the quit command Q is entered...
triumphost 120 Posting Whiz
Ok well if u just want the program to output the data shown here then you start like this:
#include <iostream>
#include <math.h>
int main()
{
cout<<" DATA HERE \n";
}
That is as small as a program can get... search up hello world if your just begining
triumphost 120 Posting Whiz
OMG OMG I got it to work with u guys tips!! I kept getting error about undefined reference to winMain@16 so i took out what that guy above you told me to take out then I removed the stdafx.h header and added these two things to Project -> Project Options (Alt+P) -> Parameters -> Linker:
-lIphlpapi
-lNetapi32
And clicked Ok and now when I compile it works perfect!! TY GUYS SO MUCH!!! Ive been trying that for days
triumphost 120 Posting Whiz
the piece that wont compile in dev c++ is this piece it gives two simple errors but i cant figure out how to fix it
#define _WIN32_WINNT 0x0500
#define _WIN32_IE 0x0500
#include "stdafx.h"
#include <Windows.h>
#include <lm.h>
#include <assert.h>
#include <iostream>
#include <winuser.h>
#include <stdlib.h>
#include <string>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <shlobj.h>
#include <direct.h>
#pragma comment(lib, "Netapi32.lib")
using namespace std;
// Prints the MAC address stored in a 6 byte array to stdout
static void PrintMACaddress(unsigned char MACData[])
{
printf("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
}
// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
unsigned char MACData[8]; // Allocate data structure for MAC (6 bytes needed)
WKSTA_TRANSPORT_INFO_0 *pwkti; // Allocate data structure for Netbios
DWORD dwEntriesRead;
DWORD dwTotalEntries;
BYTE *pbBuffer;
// Get MAC address via NetBios's enumerate function
NET_API_STATUS dwStatus = NetWkstaTransportEnum(
NULL, // [in] server name
0, // [in] data structure to return
&pbBuffer, // [out] pointer to buffer
MAX_PREFERRED_LENGTH, // [in] maximum length
&dwEntriesRead, // [out] counter of elements actually enumerated
&dwTotalEntries, // [out] total number of elements that could be enumerated
NULL); // [in/out] resume handle
assert(dwStatus == NERR_Success);
pwkti = (WKSTA_TRANSPORT_INFO_0 *)pbBuffer; // type cast the buffer
for(DWORD i=1; i< dwEntriesRead; i++) // first address is 00000000, skip it
{ // enumerate MACs and print
swscanf((wchar_t *)pwkti[i].wkti0_transport_address, L"%2hx%2hx%2hx%2hx%2hx%2hx",
&MACData[0], &MACData[1], &MACData[2], &MACData[3], &MACData[4], &MACData[5]);
PrintMACaddress(MACData);
}
// Release pbBuffer allocated by above function
dwStatus = NetApiBufferFree(pbBuffer);
assert(dwStatus == NERR_Success);
}
triumphost 120 Posting Whiz
This is my stdafx header file but when i comment out the header file it says at the end of the error part that I forgot to add stdafx.h to my code and it didnt compile... also when i comment out that header file it says it skipped all the other headerfiles looking for a precompiled header: stdafx
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
the small piece of code is the lower part of the large code but I cant get the small one to compile in VC++ and cant get the large part to compile in DEV C++ dunnno y
triumphost 120 Posting Whiz
wow he posted my code corrected as his own... oh my and on the wrong post...
triumphost 120 Posting Whiz
I dont UnderStand why it still wont compile in VC++ 2008 express edition.... someone pls help =( Also why wont the above code work in Dev C++
#define _WIN32_WINNT 0x0500
#define _WIN32_IE 0x0500
#include "stdafx.h"
#include <Windows.h>
#include <lm.h>
#include <assert.h>
#include <iostream>
#include <winuser.h>
#include <stdlib.h>
#include <string>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <shlobj.h>
#include <direct.h>
using namespace std;
int main()
{
cout<<"Creating ProELicense Folder!\n";
// get the path to the current users my documents folder
// storing it in an LPSTR
LPSTR userDocsPath = new CHAR[MAX_PATH];
SHGetSpecialFolderPath(0, userDocsPath, CSIDL_PERSONAL, 0);
// now copy the path into a std::string
std::string path = std::string(userDocsPath);
// delete the LPSTR as we don't need it any more...
delete userDocsPath;
// Now you've got the path to your users 'My Documents' folder
// stored in path, you can append any further directories onto it.
// e.g.
path.append("/ProELicense2");
// NOTE: using forward slashes works in file paths, double backslashes are not necessary!
// Not sure you need to bother creating an
// LPSECURITY_ATTRIBUTES object seeing as you're setting it to null!
CreateDirectory(path.c_str(), 0);
cout << "\nFolder Created!\n";
Sleep(2000);
return (0);
}
triumphost 120 Posting Whiz
Take a look at the little code snippet I wrote below and you will see the freopen("CON", "w", stdout); which outputs data to a screen so try inplementing it into your code...
#include <fstream>
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
freopen("CON", "w", stdout);
}
triumphost 120 Posting Whiz
Ok well I got your PM but the thing is if you cant use the modulo sign (%) then you may be able to use this... you better be greatful cuz this is a formula i had to work out myself on pencil paper...
#include <iostream>
#include <windows.h>
#include <math.h>
#include <cmath>
using namespace std;
int main()
{
int a,d,q,r;
cout<<"Numerator: \n";
cin>> a; //a is divident (numerator)
cout<<"Denominator: \n";
cin>> d;
r= abs(a - (q * d)); // d is divisor (denominator)
q=((a) / (d)); //q is quotient (plain old value without remainder)
//r is remainder
cout<< a <<" / "<< d <<" = "<< q <<" with remainder "<< r <<endl;
Sleep(3000);
return 0;
}
RELEASE NOTE: there is a bug in my code for some reason... when I ask it to output remainder, it outputs a huge!!! number which is impossible looking at the code... pick numerator 10, denominator 2, and itll still give u remainder of like 2300000 or something stupid like that so if u fix that then ur good or maybe its just my computer
triumphost 120 Posting Whiz
Doesnt exactly compile for me for whatever reason but im guess thats how you go about it... found it on this forum... And yes you should search how to do stuff rather than getting spoon fed cuz no one will just write code without you putting in effort... im only helping you start off... if the following compiles for you then ur good other than that edit and do whatever you want...
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <windows.h>
using namespace std;
int main(void)
{
int numerator=42, denominator=5, quotient, <strong class="highlight">remainder</strong>;
divide(numerator,denominator,"ient,&<strong class="highlight">remainder</strong>);
printf("numerator = %d\n", numerator);
printf("denominator = %d\n", denominator);
printf("quotient = %d\n", quotient);
printf("<strong class="highlight">remainder</strong> = %d\n", <strong class="highlight">remainder</strong>);
if (remainder > 0)
{
cout<<"Calculations did not come out to a whole number!\n";
}
else
cout<<"The remainder is 0, calculations = whole number
return 0;
}
/* my output
numerator = 42
denominator = 5
quotient = 8
<strong class="highlight">remainder</strong> = 5
*/
triumphost 120 Posting Whiz
Gosh oh my I dont usually post code just like that for someone's hmk assignment so im only going to post a partial example which does compile and work but it only gives you and idea of what you are looking for... It may not be EXACTLY what you are looking for but it seems like it is of some help... wonder why no one else is posting shudnt be too hard...
#include <iostream>
#include <windows.h>
#include <string.h>
using namespace std;
int main()
{
string url;
cout<<"Please Enter a website: \n";
cin>>url;
if (url.find('.gov') != string::npos)
{
cout<<"website = valid\n";
}
else if (url.find('.edu') != string::npos)
{
cout<<"website = valid\n";
}
else if (url.find('.org') != string::npos)
{
cout<<"website = valid\n";
}
else
cout<<"website = invalid\n";
Sleep(2000);
}
Yes i know there are errors and you can figure out what is wrong with it and fix it to suit yourself... It still compiles perfectly though so Enjoy
triumphost 120 Posting Whiz
Yes I know its a long code and it will get longer but there is a compiler error in the int main ()
First Visual C++ 2008 Express edition error
------ Build started: Project: MAC ADDRESS, Configuration: Debug Win32 ------
Compiling...
MAC ADDRESS.cpp
warning C4603: '_WIN32_WINNT' : macro is not defined or definition is different after precompiled header use
Add macro to precompiled header instead of defining here
(3) : use of precompiled header
(2) : warning C4603: '_WIN32_IE' : macro is not defined or definition is different after precompiled header use
Add macro to precompiled header instead of defining here
(3) : use of precompiled header
(53) : warning C4996: 'swscanf': This function or variable may be unsafe. Consider using swscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(575) : see declaration of 'swscanf'
(81) : warning C4996: 'freopen': This function or variable may be unsafe. Consider using freopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(252) : see declaration of 'freopen'
(86) : warning C4996: 'freopen': This function or variable may be unsafe. Consider using freopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(252) : see declaration of 'freopen'
(165) : error C2664: 'SHGetSpecialFolderPathW' : cannot convert parameter 2 from 'LPSTR' to 'LPWSTR'
Types pointed to are …
triumphost 120 Posting Whiz
THX A BILLION well I searched my errors and solved it, seems like the CSIDL_MYDOCUMENTS is no longer a valid command, it changed to CSIDL_PERSONAL after windows 2000, also I had to put
#define _WIN32_WINNT 0x0500
#define _WIN32_IE 0x0500
before I input any of my includes...
triumphost 120 Posting Whiz
These are the new errors I get when using that code =(
In function `int main()':
22 `CSIDL_MYDOCUMENTS' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
22 C:\Documents and Settings\Owner\Desktop\Untitled1.cpp `SHGetSpecialFolderPath' undeclared (first use this function)
triumphost 120 Posting Whiz
I think I have to the code right cuz it all compiles perfectly except when its done running, and I go to my documents, I dont see my directory...
#include <iostream>
#include <windows.h>
#include <winuser.h>
#include <stdlib.h>
#include <string>
#include <stdio.h>
#include "stdafx.h"
#include <lm.h>
#include <assert.h>
#include <fstream>
#include <algorithm>
#include <shlobj.h>
#include <direct.h>
using namespace std;
int main()
{
char user[100]="";
DWORD size=100;
GetUserName(user,&size);
char path[255]="";
sprintf(path,"C:\\Document And Settings\\%s\\My Documents\\",user);
string str;
string base="C:\\Document And Settings\\user\\My Documents\\OMG";
str=base;
str.replace(25,4,user,0,100);
LPSECURITY_ATTRIBUTES attr;
attr = NULL;
CreateDirectory(str.c_str(), attr);
cout << "\nFolder Created!\n";
}
triumphost 120 Posting Whiz
Ok the code below is supposed to edit a file called license.dat and replace texts in it... it works great it does all that but I want to implement user input in it. By this I mean I want the user to be able to enter the drive letter for the Drive E so that if the drive is different on their computer it will still work.
Will the cin>> X work cuz I tried that and for whatever reason it gives me a huge error. how would I got about implemeting that.
std::ifstream ifile("E:\\Pro. Engineering F000\\ProELicense\\license.dat",std::ios::binary);
#include <iostream>
#include <windows.h>
#include <winuser.h>
#include <stdlib.h>
#include <string>
#include <stdio.h>
#include "stdafx.h"
#include <lm.h>
#include <assert.h>
#include <fstream>
#include <algorithm>
using namespace std;
int main()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
string HostID;
ifstream in("C:\\Physical-Address.txt");
if (!in)
{
cout << "There was a problem with opening the file for reading." << endl;
}
else
{
getline (in,HostID);
cout<< HostID << endl;
}
Sleep(1000);
std::ifstream ifile("E:\\Pro. Engineering F000\\ProELicense\\license.dat",std::ios::binary);
ifile.seekg(0,std::ios_base::end);
long s=ifile.tellg();
char *buffer=new char[s];
ifile.seekg(0);
ifile.read(buffer,s);
ifile.close();
std::string txt(buffer,s);
delete[] buffer;
size_t off=0;
while ((off=txt.find("YOUR_HOST_ID",off))!=std::string::npos)
txt.replace(off,sizeof("YOUR_HOST_ID")-1,HostID);
std::ofstream ofile("C:\\license.dat");
ofile.write(txt.c_str(),txt.size());
return (0);
}
triumphost 120 Posting Whiz
Here much easier... =) This finds the sum of all the values between the range of values you enter.
#include <iostream>
using namespace std;
int main()
{
long Sum = 0;
long x, y;
cout << "Enter the first #: ";
cin >> x;
cin.ignore();
cout << "Enter the last #: ";
cin >> y;
cin.ignore();
// If the last number > then the first, inverse them
if( x > y )
{
int Z;
Z = x;
x = y;
y = Z;
}
for( int Counter = x; Counter <= y; Counter++ )
Sum += Counter;
cout << "Sum of numbers from " << x << " to " << y << " = "
<< Sum << endl;
cout << "Press Enter to exit";
cin.get();
return 0;
}
triumphost 120 Posting Whiz
ok so on my computer the path to the Physical-Address file is C:\ but if I put that it doesnt write to the file so I put C:\\ and then the file shows up on the local disk, I have also edited the code and now I have this piece added and it reads it and inputs it to the string
string HostID;
ifstream myfile ("C:\\Physical-Address.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,HostID);
cout << HostID << endl;
}
myfile.close();
}
else cout << "Unable to open file";
Ok but now I need more help lol I hope u guys dont mind... but yea I need help on creating a directory in the my documents folder with the code but everyone's my documents folder is a different path.
Im assuming I use CreateDirectory()? but is that for console applications? But how can i create a directory in their my documents folder if I dont know the path...
triumphost 120 Posting Whiz
I changed that part I didnt see that I was making it print MAC Address: instead of just the result but now I need help to read that from the file and put it in a string to replace in another file
static void PrintMACaddress(unsigned char MACData[])
{
printf("%02X-%02X-%02X-%02X-%02X-%02X\n",
MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
}
triumphost 120 Posting Whiz
Below is the code that I have to find the Mac address of any pc (physical host ID) I struggle to make it print to a file but now i have a problem... It prints MAC Address: XX-XX-XX-XX-XX-XX to C:\\Physical-Address.txt but I only want it to print the XX-XX-XX etc part... and since I cant get it to do that I decided I want to erase the "MAC Address: " part of the file and print the XX-XX to a new file inorder to put it into a string... ive been working on this for 3 days now and cant find an answer =( I tried getline, fstream commands so i left those headers in the code still incase they are needed... Also I had to redirect the mac address to a text file since i dont know how to get it into a string any help of any sort is appreciated but pls remember Im very new to programming and i self teach... been about a 3 months of straight studying...
#include "stdafx.h"
#include <Windows.h>
#include <lm.h>
#include <assert.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <winuser.h>
#include <fstream>
#pragma comment(lib, "Netapi32.lib")
using namespace std;
// Prints the MAC address stored in a 6 byte array to stdout
static void PrintMACaddress(unsigned char MACData[])
{
printf("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
}
// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
unsigned char MACData[8]; // Allocate data structure for MAC (6 bytes needed) …