Hello! I have been having a hard time trying to properly concat two strings (or char[]) into one string. here is my code so far:
// Includes
#include "template.h"
#include <stdio.h>
#include <direct.h>
#include <cstring>
#define GetCurrentDir _getcwd
char cCurrentPath[FILENAME_MAX];
// Namespace
using namespace AGK;
app App;
void app::Begin(void)
{
agk::SetVirtualResolution (1920,1200);
agk::SetClearColor( 151,170,204 ); // light blue
agk::SetResolutionMode(0);
agk::SetSyncRate(60,0);
agk::SetScissor(0,0,0,0);
net = agk::HostNetwork("PAD","host",4444);
if(!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
{
agk::Message("error trying to get current dir!!!");
}
agk::SetErrorMode(0);
cCurrentPath[sizeof(cCurrentPath) - 1] = '\0';
}
void app::Loop (void)
{
char DirStr[FILENAME_MAX];
agk::Print( agk::ScreenFPS() );
agk::Sync();
strcat(DirStr, cCurrentPath);
strcat(DirStr, "\\hello");
agk::Print(DirStr);
if(dirExists(std::string(DirStr)))
{
agk::Print("hello is found");
}
else
{
agk::Print("hello is not found");
}
if(net > 0)
{
int msg = agk::GetNetworkMessage(net);
if(msg > 0)
{
LPSTR addr = agk::GetNetworkMessageString(msg);
if(addr == "GET_APP")
{
title = agk::GetNetworkMessageString(msg);
if(dirExists(convertLPSTRtoString(title)))
{
}
}
if(addr == "FIND_APP")
{
}
if(addr == "SEND_APP")
{
}
}
}
}
std::string app::Appends(std::string a, std::string b)
{
a += b;
return a;
}
std::string ExePath() {
char buffer[MAX_PATH];
GetModuleFileName( NULL, buffer, MAX_PATH );
std::string::size_type pos = std::string( buffer ).find_last_of( "\\/" );
return std::string( buffer ).substr( 0, pos);
}
bool app::dirExists(const std::string& dirName_in)
{
DWORD ftyp = GetFileAttributesA(dirName_in.c_str());
if (ftyp == INVALID_FILE_ATTRIBUTES)
return false; //something is wrong with your path!
if (ftyp & FILE_ATTRIBUTE_DIRECTORY)
return true; // this is a directory!
return false; // this is not a directory!
}
void app::End (void)
{
}
std::string app::convertLPSTRtoString(LPSTR str)
{
std::string stdstr = str;
return stdstr;
}
LPSTR app::convertStringToLPSTR(std::string str)
{
LPSTR s = const_cast<char *>(str.c_str());
return s;
}
The code can be confusing, but the only part I am having trouble is where I do:
strcat(DirStr, cCurrentPath);
strcat(DirStr, "\\hello");
I have tried to delete the DirStr with delete(DirStr) and delete[] (DirStr) and it runs into an exception. If I leave it alone and do not delete it, it freezes and crashes. I will try to figure out the exception, but I do need help! Thank you in advance!
website: http://worksimpleintelligen.wix.com/parkers-apps
facebook: https://www.facebook.com/ParkersApps
youtube: http://www.youtube.com/user/mrsovr