Answer the question
In order to leave comments, you need to log in
How to return a char* string by passing variables to it?
Hello! I faced such a problem, let's start from the beginning:
I am creating a program that will generate the initial code of bots for VK using PHP, Python.
So: what problem I faced: when creating a file, I need to write there the code of a certain bot with a certain format. For example, I chose - 1. Create a bot for a group 2. Bot in Python
Next, I have a function into which it is passed what the bot is created for, and with what extension, here is the code:
char* getCode(QString mode, QString script) {
// <...> Deleted
else if(mode == "b" && script == "py") {
return
"import vk_api\n"
"import requests\n"
"session = requests.Session()\n"
"login, password = '%s', '%s'" // Problem
"";
}
// Если выбран бот для Группы( g ) и на php ( Там выше QString переменные в коде, но я их суда не добавил )
else if (mode == "g" && script == "php") {
return "<?php\n"
"\n"
"// Thanks for using BotHelper\n"
"// Author: Danil Romanov (vk: *******) \n"
"\n"
"include \"vk_api.php\";\n"
"const VK_KEY = \"%s\";\n" // Problem \ Проблема
"const ACCESS_KEY = \"%s\"; \n" // Problem \ Проблема
"const VERSION = \"5.81\";\n"
"$vk = new vk_api(VK_KEY, VERSION); \n"
"$data = json_decode(file_get_contents('php://input'))\n"
"if (data->type == \"confirmation\") {\n"
" exit(ACCESS_KEY);\n"
"}\n"
"$vk->sendOK();\n"
"// Enter this your code . . .";
}
else {
QMessageBox::information(0, "Error", "Ошибка: неправильно переданы переменные в функцию\nПожалуйста, сообщите создателю программы об ошибке\nВК: *****");
}
}
// Если выбран бот на Питоне(py) и для беседы(b) ( Там выше QString переменные в коде, но я их суда не добавил )
else if(mode == "b" && script == "py") {
return
"import vk_api\n"
"import requests\n"
"session = requests.Session()\n"
"login, password = '%s', '%s'", ui->lineEdit_7->text() // Не видит
ui
. Answer the question
In order to leave comments, you need to log in
This is how it's done
QString i; // current file's number
QString total; // number of files to process
QString fileName; // current file's name
QString status = QString("Processing file %1 of %2: %3")
.arg(i).arg(total).arg(fileName);
const auto text=QString(R"(
My program is %1
it's written by %2
for %3
)").arg("good","nice gay","fun and profit");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question