【发布时间】:2013-12-11 16:45:17
【问题描述】:
过去几天我一直在尝试修复此代码,但它无法正常工作..
char* appdata = getenv("APPDATA");
char* firstloglocation = strcat(appdata, "\\path\log1.txt");
这是有效的,但我需要这个:
char* appdata = getenv("APPDATA");
char* firstloglocation = strcat(appdata, "\\path\log1.txt");
char* secondloglocation = strcat(appdata, "\\path\log2.txt");
一旦我添加了第二行代码,它就不再做任何事情了
这两个日志都必须上传到我的 FTP 服务器,其余代码工作正常
这是原始代码:
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
#include <wininet.h>
#include <ctime>
#include <iostream>
#pragma comment(lib, "wininet")
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
srand((unsigned)time(NULL));
int seedone=rand();
int seedtwo=rand()*3;
int seedboth = seedone + seedtwo;
char randomnumber[99];
itoa(seedboth, randomnumber, 10);
char* appdata = getenv("APPDATA");
char* log1 = strcat(appdata, "\\DVcA\\log.txt"); // Location of the first log
char* log2 = strcat(appdata, "\\DVcB\\log.txt"); // Location of the second log
HINTERNET hInternet;
HINTERNET hFtpSession;
hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
hFtpSession = InternetConnect(hInternet, "SERVER", INTERNET_DEFAULT_FTP_PORT, "USERNAME", "PASSWORD", INTERNET_SERVICE_FTP, 0, 0); // Server details
FtpCreateDirectory(hFtpSession, "DVcA"); // Create directory
FtpSetCurrentDirectory(hFtpSession, "DVcA"); // Go to folder
FtpPutFile(hFtpSession, log1, randomnumber, FTP_TRANSFER_TYPE_BINARY, 0);
FtpSetCurrentDirectory(hFtpSession, ".."); // Go back to root folder
FtpCreateDirectory(hFtpSession, "DVcB"); // Create directory
FtpSetCurrentDirectory(hFtpSession, "DVcB"); // Go to folder
FtpPutFile(hFtpSession, log2, randomnumber, FTP_TRANSFER_TYPE_BINARY, 0);
InternetCloseHandle(hFtpSession);
InternetCloseHandle(hInternet);
return 0;
}
【问题讨论】:
标签: strcat