所以我试着通过循环char数组并检查相同的char字符串来编写一个函数来检查一个单词是否在一个句子中.只要句子没有任何空格,该程序就可以运行.我用Google搜索,他们都是一样的建议;
cin.getline
Run Code Online (Sandbox Code Playgroud)
但是,无论我实现它,它要么不运行,要么跳过整个输入并直接输出.
我怎么能占空间?
#include <iostream>
using namespace std;
bool isPartOf(char *, char *);
int main()
{
char* Word= new char[40];
char* Sentence= new char[200];
cout << "Please enter a word: ";
cin >> Word;
cout << endl << "Please enter a sentence: ";
//After Word is input, the below input is skipped and a final output is given.
cin.getline(Sentence, 190);
cout << endl;
if (isPartOf(Word, Sentence)==true)
{
cout << endl << "It is part of it.";
}
else
{ …Run Code Online (Sandbox Code Playgroud) 我正在尝试用于UrlFetchApp访问外部(Enjin)API 并获取 JSON 信息块。单独运行该函数(基本上是一个 get 函数)提供正确的 HTTP 响应。但是,当从onEdit()触发器事件调用该函数时,Logger 不记录任何响应?
从触发器发出外部 API 请求时有区别吗?
这是函数本身:
function getUserID(name) {
var url = "URLHERE";
// Make a POST request with a JSON payload.
var data = {
'jsonrpc':'2.0',
'id': '12345',
'params':{
'api_key': '123'
},
'method': 'UserAdmin.get'
};
var options = {
'method' : 'post',
'contentType': 'application/json',
'payload' : JSON.stringify(data)
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
return 1;
}
Run Code Online (Sandbox Code Playgroud) javascript triggers google-sheets urlfetch google-apps-script
我有一个更大的任务,其中包含此功能。这是说明;
定义一个名为 isPartOf 的 C++ 函数,带有两个指向 C 字符串的参数指针(即 char * 类型,不是来自尚未详细声明的 C++ 数据类型 string ),并返回一个布尔值。
本质上,该函数应该检查第一个参数指针指向它的字符串是否是第二个参数指针指向它的字符串的一部分。
示例: isPartOf(“心脏”、“高血压心脏病”) 返回 true 返回 isPartOf(“螺钉”、“涉及轮椅的案件”) 返回 false。
我已经学习 C 一年了,才开始学习 C++,我发现很难理解“char *”和参数的一般用法。我花了一段时间才理解指针,现在参数让我迷失了。我已经尝试过这段代码,可能包含 * 和 & 的所有可能的迭代,只是为了看看它是否有效,但它不起作用。
#include <iostream>
using namespace std;
void isPartOf(char *, char *);
int main()
{
char * Word;
char * Sentence;
cout << "Please enter a word: ";
cin >> Word;
cout << endl << "Please enter a sentence: ";
cin >> Sentence;
cout << endl;
isPartOf(Word, Sentence);
if …Run Code Online (Sandbox Code Playgroud) c++ ×2
cin ×1
javascript ×1
parameters ×1
pointers ×1
spaces ×1
string ×1
triggers ×1
urlfetch ×1